[英]how can i force to make it to only string
Hello How can i force to make the nname to only string input because even though i put number it still continue to the next function and i only like it to be a name of the people nname= str(input()) does not work thats why im asking if there is other alternative to make it work with only a string您好,我如何强制将 nname 设置为仅输入字符串,因为即使我输入数字,它仍然会继续到下一个 function 并且我只喜欢它是人名 nname= str(input()) 不起作用为什么我要问是否有其他选择可以让它只使用一个字符串
print("Good Day Welcome To our Shop.")
mnu = ["Milktea","Foods", "Drinks", "Dessert"]
lsa = ["1.Matcha", "Taro", "Winter Melon", "Okinawa", "Chocolate",
"Cheese Cake"]
fds = {'Chicken'}
shot = ["tubig"]
mtms = ["ice cream"]
laht = []
print("Hi what would you like to be called, "
"So we can inform you if your order is ready")
def cstmrinfo(name):
print("Okay " + name, "So what would you like to get " )
print(*mnu,sep = "\n")
nname= input().lower()
def kuha_order():
while True:
order = input()
if (order == "Milktea") or (order == "milktea"):
print(lsa)
laht.append(order)
break
elif (order == "Foods") or (order == "foods"):
print(fds)
laht.append(order)
break
elif (order == "Drinks") or (order == "drinks"):
print(shot)
laht.append(order)
break
elif (order == "Dessert") or (order == "dessert"):
print(mtms)
laht.append(order)
break
else:
print("Sorry you input a thing that is not available on our menu, "
"Please Try again:")
continue
def pnglhtn():
while True:
print("I Would like to get a: ")
qwe = input()
if qwe in lsa:
print(qwe)
elif qwe in fds:
print(qwe)
elif qwe in shot:
print(qwe)
elif qwe in mtms:
print(qwe)
else:
print("There is no such thing like that ")
continue
dmi = int(input("How Many Servings Would you Like: "))
laht.append(qwe)
laht.append(dmi)
print("So " + pngln, "you Like a " + str(laht[:2]))
print (dmi, "Serves of: " + str(laht[:2]))
break
cstmrinfo(nname)
kuha_order()
pnglhtn()
When using the logical "or" operator in an if...else statement in python you have to repeat the variable as well as the value (i know that sounds confusing so look at the example)在 python 的 if...else 语句中使用逻辑“或”运算符时,您必须重复变量和值(我知道这听起来令人困惑,所以请看示例)
this means that this won't work:这意味着这不起作用:
if order == "Milktea" or "milktea":
the correct formation should be:正确的编队应该是:
if (order == "Milktea") or (order == "milktea"):
alternatively if you want to simply check one variable against a range of values check out the match...case statements in python 3.10+: https://learnpython.com/blog/python-match-case-statement/或者,如果您只想根据一系列值检查一个变量,请查看 match...case 语句 python 3.10+: https://learnpython.com/blog/python-match-case-statement/
###################################################### ################################################# ####
Remove the if order in mmu line and indent the corresponding else (code listed below)删除 mmu 行中的 if 顺序并缩进对应的 else(代码如下)
def kuha_order():
while True:
order = input()
print(order)
if order == "Milktea":
print(flvrs)
laht.append(order)
break
elif order == "Foods":
print(pgkn)
laht.append(order)
break
elif order == "Drinks":
print(shot)
laht.append(order)
break
elif order == "Dessert":
print(mtms)
laht.append(order)
break
else:
print("Sorry you input a thing that is not available on our menu")
continue
you can combine this with my answer above to get what you need:)你可以把它和我上面的答案结合起来得到你需要的东西:)
You can use either lower() or upper().您可以使用lower() 或upper()。 Please check the following answer:
请检查以下答案:
if order.lower()=="milktea":
print(flvrs)
laht.append(order)
break
OR或者
if order.upper()=="MILKTEA":
print(flvrs)
laht.append(order)
break
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.