I'm asking you a question while studying Python commands.

Asked 2 years ago, Updated 2 years ago, 125 views

I don't know what to do with Python, so I was studying the def syntax, and I asked because I had a question.

The contents below are what I did.

Questions

Is there a way to use the def phrase as a plural number and use it twice for the glass and drink?

When I input(), it says "I'm" or "Cup" separately, so it overlaps, so you ordered 2 cups of cider. Is there a way to make an exception and ask again or change it so that an error mark appears?

python def

2022-09-22 18:41

1 Answers

If you're a beginner, try it and ask questions. That's how you improve your skills.

def order_beverage():
    drink = input ('Tell me what you want to order')

    while True:
        confirm = input(f'{drink} correct? (Y/N) Cancel:Q')
        if confirm in ['Y', 'y']:
            return drink
        elif confirm in ['Q', 'q']:
            return ''


def order_cnt():
    while True:
        order_cnt = input('How many cups would you like to order?')
        try:
            order_cnt_number = int(order_cnt)
        except ValueError:
            Please enter only print(f)' numbers.[Not a number: {order_cnt}]')
        else:
            return order_cnt_number

ordering_flag = True

while ordering_flag:
    drink = order_beverage()
    if drink:
        ordering_flag = not ordering_flag
        cnt = order_cnt()

A glass of print(f'{drink} {cnt} has been ordered.')


2022-09-22 18:41

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.