2016-11-21 56 views
0

我有我的计划一吨的麻烦。过去5个小时我到处寻找,似乎无法找到任何与我正在尝试做的事情有关的事情(无论如何我都能理解)。转换用户字输入价格

我创建一个比萨饼程序,并试图获得大小的输入(如大,中,小)。该程序将要求用户输入大,中,小,价格为空白列表。

我已经设置了价格,但我完全搞不清我需要怎么大,中,小的输入转换成实际的价格,我为大小设置。

这是我的代码。任何帮助是极大的赞赏。我也半知道我不应该使用int来定价,但是我查看的所有命令都是针对Python的老版本或其他东西。

目前使用Python 3.5。

print ("Welcome to My Pizzeria!") 
name = input("What name is the order under? ") 
size = input("What size would you like? ") 
top = input("Would you like to add sausage? ") 
money = 0 
total = (size+top) 
if size == 'large': 
    total = int(money) + 10.00 
elif size == 'medium': 
    total = int(money) + 7.00 
elif size == 'small': 
    total = int(money) + 5.00 
money = total 
if top == 'no': 
    total = int(money) + 0.00 
elif top == 'yes': 
    total = int(money) + 1.00 
    pass 
print ("Your total is $" + str(total)) 
print ("Thank you for your order " + name + "!") 
+0

什么是'money',是基础价格是多少?因为你的情况它被设置为'None',这是不正确的。国际海事组织它应该是一些固定的整数值或者你可能想从用户采取这个输入 –

+0

钱只是我试图测试一些想法。我已经更新了我目前正在玩弄的代码。如果需要更多比萨饼,我必须稍后让我的程序循环。基本上所有我问的是我怎么能做一个伪“if”声明。喜欢:如果回答“你想要什么尺寸”很大,那么总共添加10.00 – Zeus

回答

0

在这种情况下,我认为这是你想要的。 我已经装满钱的10伪价值,虽然我仍然包裹在INT的情况下,你拥有了它在海峡格式。

print ("Welcome to My Pizzeria!") 
name = input("What name is the order under? ") 
size = input("What size would you like? ").lower() 
top = input("Would you like to add sausage? ").lower() 
money = 0 
if size == 'large': 
    total = int(money) + 10.00 
elif size == 'medium': 
    total = int(money) + 7.00 
elif size == 'small': 
    total = int(money) + 5.00 
money = total 
if top == 'no': 
    total = int(money) + 0.00 
elif top == 'yes': 
    total = int(money) + 1.00 
print ("Your total is $" + str(total)) 
print ("Thank you for your order " + name + "!") 

OP

Welcome to My Pizzeria! 
What name is the order under? Saurabh 
What size would you like? Large 
Would you like to add sausage? Yes 
Your total is $11.0 
Thank you for your order Saurabh! 
+0

非常感谢!我真的很感谢你的帮助。我在你的代码中添加了几行代码,我即将尝试添加循环语句。用新代码更新原始帖子。 – Zeus

0

该代码会要求用户回答,直到他们提供一个有效的答案,然后打破无限循环,进入到下一个。您不需要变量“money”,因为可以在整个脚本中添加总数而不需要额外的变量。 'x + = 1'只是'x = x + 1'的简称。希望这可以帮助!

print ("Welcome to My Pizzeria!") 
name = input("What name is the order under? ") 
total = 0 

while 1: 
    size = input("What size would you like? ").lower() 
    if size == 'large': 
     total += 10.00 
     break 
    elif size == 'medium': 
     total += 7.00 
     break 
    elif size == 'small': 
     total += 5.00 
     break 
    else: 
     print("Sorry, that is not an option! Please order something else!") 

while 1: 
    top = input("Would you like to add sausage? ").lower 
    if top == 'no': 
     total += 0.00 
     break 
    elif top == 'yes': 
     total += 1.00 
     break 
    else: 
     print("Sorry, that is not an option! Please order something else!") 

print ("Your total is $" + str(total)) 
print ("Thank you for your order " + name + "!")