Python implements an Automatic Beverage Sales program code sharing and python program code

Source: Internet
Author: User

Python implements an Automatic Beverage Sales program code sharing and python program code

When I was writing this program, I had been learning Python for nearly one hundred hours. On CSDN, I saw someone asking for help using Python to write a program for auto-selling drinks. I thought, try to write a practical vending program. Of course, it is just to implement basic functions. You are welcome to give pointers and learn from new users.

Running Environment: Python 2.7

# Encoding = UTF-8loop = Truemoney = 0 while loop: x = raw_input ('prompt: Please input gold coins, end coin press "q" Key') if x = 'q ': if money = 0: print 'error: You have not invested a banknote. Please invest at least one banknote before you can purchase the 'else: print'. Tip: You have ended coin writing, on the product purchase page, click 'loop = False else: try: x = int (x) money + = x print '. The system prompts you to pay for this coin', x, 'RMB, you have invested a total of coins ', money,' Renminbi 'except t Exception, e: print' error: Your gold coin system is not recognized. Please try again. Thank you! 'Goodlist = {'Coca-Cola ': 2.5, 'Fruit Orange': 3, 'milk tea': 1.5, 'canadian treasure ': 4} I = 0 print' select a product: 'for x in GoodList: I + = 1 print' No. ', I, 'item name', x, 'price ', goodList [x] print fanwei = range (len (GoodList) loop = Truewhile loop: o = raw_input ('prompt: Enter the product number you want to purchase, press the "q" key to end purchasing ') if o = 'q': loop = False else: try: o = int (o) if o> = 1 and o <= len (GoodList): I = 0 for x in GoodList: I + = 1 if I = o: if money> = GoodList [x]: money-= GoodList [x] print 'prompt: The items you purchased are: ', x,', price: ', GoodList [x],', and you still have: ', money, 'yuan Renminbi 'if money = 0: loop = False else: print' error: Your balance ', money,' the dollar is insufficient to buy this item ', x, '[', GoodList [x], 'yuan]' else: print 'error: the product number you entered does not exist. Please enter 'failed t Exception, e: print' again. Error: enter the correct product number. Thank you for your cooperation! 'If money> 0: print 'prompt: the system will look for you,', money, 'RMB. Welcome to 'else: print' next time. Prompt: Your balance has been used up, welcome'

Program a vending machine software that processes a drink with a unit price of 5 cents, and use the Causal Method to Design test cases and implement

This is simple .....

Dim sumMoney As Integer = 100
Public Sub Test (ByVal money As Integer, ByVal options As String)
'If you invest 5 cents or 1 yuan worth of coins, place the button of orange juice or beer, then the corresponding drinks will be sent out.
'If there is no change to find the vending machine, then a red light that shows the change, then after you put a 1 Yuan coin and place the button, the drinks are not sent out, and the 1 Yuan coin is also withdrawn;
'If you have any change, the red light of the change is turned off. Five cents are returned when you send out the drink ."
Dim fiveTea As String = "tea"
Dim oneCoffee As String = "coffee"
Response. Write ("Welcome, please coin/and select an item! ")
Select Case CType (options, String)
Case options = fiveTea
Response. Write ("You selected tea! $5 ")
If money = 5 Then
Response. Write ("your item" & fiveTea & "purchased successfully! Thank you for coming ")
ElseIf money <5 Then
Response. Write ("sorry, the money is not enough. Please pay for it! ")
ElseIf money> 5 Then
Dim s As Integer
If sumMoney> money Then
S = money-5
Response. Write ("your item" & fiveTea & "purchased successfully! Contact you "& s &" Yuan ")
Else
Response. Write ("sorry, you cannot get the money! Thank you! Please collect your money "& money &"")
End If
End If
Case options = oneCoffee
Response. Write ("You selected coffee! $1 ")
If money = 1 Then
Response. Write ("your item" & oneCoffee & "purchased successfully! Thank you for coming ")
ElseIf money & lt ...... remaining full text>

The following describes the specifications of the software for black box testing of an automatic beverage vending machine.

The shooman formula:

Among them, IT = 105, MTTF1 = 0.4, T1 = 160, n1 = 100, MTTF2 = 2, T2 = 320, n2 = 300. D:

(1) The total number of errors inherent in the solution is ET = 350, and K = 1000.
(2) Set MTTF = 10,

Returns x = 340. By the reliability accumulation curve EC (t) = ET (1-e-K1 t ),
100 = 350 (1-e-160K1)
300 = 350 (1-e-320K1)
Therefore, 3-3 * e-160K1 = 1-e-320K1
2 = 3 * e-160K1-e-320K1 set x = e-160K1
X2-3x + 2 = 0
Obtain x1 = 2, x2 = 1, K1 = ln (x1)/(-160) =-0.693/160? 0.00433.
Because ln (x2)/(-160) = 0, remove
Substitution: 340 = 350 (1-e-K1 t) = 350 (1-e-0.00433 t)
350e-0.00433 t = 10
T = (ln (35)/0.00433? 821 (hours)
Therefore, it takes 821 hours to test and debug the program to make MTTF = 10.
(3) functional relationship between MTTF and test time t:
Because EC (t) = ET (1-e-K1 t), ET-EC (t) = ET e-K1 t. Into shooman formula:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.