用python写一个 点餐代码--急急急 !!! 希望高人帮忙! 求助!用python编写21点程序的问题。。。

\u6025\u6025\u6025\uff01\u6c42\u5927\u795e\u5e2e\u5fd9\u505a\u4e2aPython\u5728\u7ebf\u70b9\u9910\u5c0f\u8f6f\u4ef6

User={}
List=open("USER.txt","r")
for _list in List:
_List=_list.split()
User[_List[0]]=_list[2]
List.close()
List1=open("USER.txt","a")
print ("Welcome")
print ("\u662f\u5426\u9700\u8981\u6ce8\u518c\uff1f\uff08Y/N\uff09:")
a1=True
while a1:
_a=input("\u8bf7\u8f93\u5165\u9009\u62e9\uff1a")
if _a not in ["Y","y","N","n"]:
print ("WARRING:\u8bf7\u8f93\u5165Y\u6216\u8005N\u8fdb\u884c\u9009\u62e9")
continue
else:
a1=False
a1=True
if _a in ["Y","y"]:
print ("----------------\u6ce8\u518c\u754c\u9762----------------")
while a1:
a_id=input("\u8bf7\u8f93\u5165ID\uff1a")
if a_id in User:
print ("ID\u88ab\u5360\u7528\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff01")
continue
else:
while a1:
a_pass=input("\u8bf7\u8f93\u5165\u5bc6\u7801\uff1a")
a_pass1=input("\u8bf7\u518d\u6b21\u8f93\u5165\u5bc6\u7801\uff1a")
if a_pass!=a_pass1:
print ("\u4e24\u6b21\u5bc6\u7801\u4e0d\u6b63\u786e\uff01\u91cd\u65b0\u8f93\u5165")
continue
else:

List1.write(a_id)
List1.write("\t")
List1.write(a_pass)
List1.write("\n")
print ("\u6ce8\u518c\u5b8c\u6bd5\uff0c\u5c06\u8f6c\u5165\u767b\u5f55\u754c\u9762\uff01")
a1=False

else:
None
List1.close()
print ("----------------\u767b\u5f55\u754c\u9762----------------")
a1=True
while a1:
b1=input("\u8bf7\u8f93\u5165\u8d26\u53f7\uff1a")
b2=input("\u8bf7\u8f93\u5165\u5bc6\u7801\uff1a")
try:
User[b1]
except:
print ("\u8d26\u53f7\u9519\u8bef,\u8bf7\u91cd\u65b0\u8f93\u5165\uff01")
continue
if User[b1]!=b2:
print ("\u8d26\u53f7\u5bc6\u7801\u8f93\u5165\u9519\u8bef,\u8bf7\u91cd\u65b0\u8f93\u5165\uff01")
continue
else:
a1=False
print ("----------------\u70b9\u9910\u754c\u9762----------------")
print ("1:\u8304\u5b50 10\u5143\n2:\u767d\u83dc\uff1a15\u5143\n3:\u841d\u535c\uff1a20\u5143\n4:\u8089\uff1a30\u5143")
Dict={"1":"\u8304\u5b50","2":"\u767d\u83dc","3":"\u841d\u535c","4":"\u8089"}
Price={"1":10,"2":15,"3":20,"4":30}
print ("\u8bf7\u8f93\u5165\u8981\u70b9\u7684\u83dc\u7f16\u53f7\uff08\u6ca1\u8f93\u5165\u4e00\u4efd\u83dc\u8bf7\u6309\u4e00\u6b21\u56de\u8f66\uff09\uff1a")
a1=True
_a1=1
az=[]
while a1:
ax=input("\u7b2c%s\u4efd(\u70b9Q\u9000\u51fa\u70b9\u9910)\uff1a" %(_a1))
if ax=="q" or ax=="Q":
print ("\u7ed3\u675f\u70b9\u9910\uff01\uff01\uff01")
a1=False
elif ax not in ["1","2","3","4"]:
print ("\u672a\u5f00\u53d1\u9910\u5185\u5bb9\uff01\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165")
continue
else:
az.append(ax)
_a1+=1
a1=True
total=0
while a1:
if az==[]:
print ("\u60a8\u6ca1\u6709\u70b9\u9910\uff01\uff01\uff01\uff01,\u9000\u51fa\u70b9\u9910\u7cfb\u7edf\uff01\uff01\uff01")
a1=False
else:
print ("\u60a8\u7684\u9910\u5217\u8868\uff1a")
for zz in az:
print ("%s\t%s" %(Dict[zz],Price[zz]))
total+=Price[zz]
print ("\u4e00\u5171%s\u5143" %(total))
a1=False
print ("\u6b22\u8fce\u4e0b\u6b21\u5149\u4e34\uff01\uff01")

\u9700\u8981Python3\u4ee5\u4e0a \u4e0d\u7136\u81ea\u5df1\u53bb\u6539print
\u5728PYTHON\u6240\u5728\u6587\u4ef6\u5939\u91cc\u505a\u4e00\u4e2aUSER.txt \u7528\u6765\u5b58\u50a8\u8d26\u53f7\u5bc6\u7801\u7528

import random# 1def ask_user(prompt, response1, response2): """ Ask user for a response in two responses. prompt (str) - The prompt to print to the user response1 (str) - One possible response that the user can give response2 (str) - Another possible response that the user can give """ while True: # ask user for response user_response = input(prompt) #if response is response1 or response2 then return if user_response == response1 or user_response == response2: return user_response# 2def print_card(name, num): """ print "______ draws a _____" with the first blank replaced by the user's name and the second blank replaced by the value given to the function. name (str) - the user name to print out num (int) - the number to print out """ # if the value is a 1, 11, 12, 13, print Ace, Jack, Queen, King if num == 1: num = "Ace" elif num == 11: num = "Jack" elif num == 12: num = "Queen" elif num == 13: num = "King" else: num = str(num) # print the string print(name, "draws a", num) # 3def get_ace_value(): """ Ask the user if they want to use a 1 or 11 as their Ace value. """ # get the value use "ask_user" function value = ask_user("Should the Ace be 1 or 11?", "1", "11") # retrun the value return int(value)# 4def deal_card(name): """ Pick a random number between 1 and 13, and print out what the user drew. name (str) - the user name to print out """ # get a random number in range 1 to 13 num = random.randrange(1, 13+1) # use "print_card" function to print out what the user drew print_card(name, num) if num > 10: # if the card is a Jack, Queen, or King, the point-value is 10 return 10 elif num == 1: # If the card is an Ace, ask the user if the value should be 1 or 11 return get_ace_value() else: return num # 5def adjust_for_bust(num): """ If the given number is greater than 21, print "Bust!" and return -1. Otherwise return the number that was passed in. num (int) - the given number """ # determine the value of num if num > 21: print("Bust!") return -1 else: return num # 6def hit_or_stay(num): """ Prompt the user hit or stay and return user's chose. num (int) - the value of a player's card hand """ if num score2: print(name1, "wins!") elif score1 < score2: print(name2, "wins!")# 9def main(): """ The main program of BlackJack game """ while True: # Ask each player for their name name1 = input("Player 1 name:") name2 = input("Player 2 name:") # Greet them print("Welcome to BlackJack", name1, "and", name2) print() # Let the first player play a turn score1 = play_turn(name1) print() # Let the second player play a turn score2 = play_turn(name2) print() # Determine who won determine_winner(name1, name2, score1, score2) # Play again if they say yes and end the loop if they say no if ask_user("Would you like to play again?", "yes", "no") == "no": breakif __name__ == "__main__": main()
\u5982\u679c\u4f60\u7684\u4f5c\u4e1a\u6b63\u597d\u4e5f\u662f\u8fd9\u4e2a\u7684\u8bdd\uff0c\u5343\u4e07\u522b\u4e00\u6a21\u4e00\u6837\u6284\u54c8\uff0c\u6309\u8fd9\u53c2\u8003\u81ea\u5df1\u6539\u4e00\u6539\uff0c\u4e0d\u7136\u4f1a\u88ab\u5224\u96f7\u540c\u7684\u3002

# coding: utf-8

menu = {
        '1': dict(name='草莓冰淇淋', price=20),
        '2': dict(name='香草冰淇淋', price=10),
        '3': dict(name='香蕉冰淇淋', price=15),
        '5': dict(name='巧克力冰淇淋', price=30),
    }

def showmenu(menu):
    for k, item in sorted(menu.items()):
        print "%(key)s: %(name)s 价格%(price).2f" % dict(key=k, **item)

def menuchoice(menu):
    while True:
        showmenu(menu)
        c = raw_input("Your Choice('.' for end): ")
        if c == '.':
            break
        else:
            yield menu.get(c)

customerchoice = filter(None, menuchoice(menu))

print "Total: %.2f" % sum(map(lambda x: x["price"], customerchoice))


扩展阅读:python 写简历 ... python简易点菜系统 ... python下载安装教程 ... python中& 是什么意思 ... python &用法 ... python 结果一块表达 ... 高中python简单点餐系统 ... python实用小程序代码合集 ... python餐厅点餐系统源代码 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网