简体   繁体   中英

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

 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)

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/

######################################################

Remove the if order in mmu line and indent the corresponding else (code listed below)

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(). 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM