Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

if-else commands registering the wrong user_input

I have a bar programm, and I’m trying to make it user interactable, with some simple if else code. However, my commands doesn’t seem to work, i.e typing the input N on a Y/N question still makes the programm print the Y response and not the N response.

Here is my current code:

import Bar_Back
import random
import time

while True:
    #Main class Person
    class Person:
        def __init__(self, name, age) -> None:
            self.name = name
            self.age = age

    #Subclass Guest
    class Guest(Person):
        def __init__(self, name, age, drinks) -> None:
            super().__init__(name, age)
            self.drinks = drinks
        
        #Prints the current Liquor Menu
        def ask_for_menu(self):
            print(f'The current liquor menu is \n{Bar_Back.Item.all_items()}')
        
        #The guests places an order which is stored in the waiter order list
        def place_order(self, order, this_waiter):
            this_waiter.add_order(order)

    #Subclass Waiter
    class Waiter(Person):
        def __init__(self, name, age, order_list = []) -> None:
            super().__init__(name, age)
            self.order_list = order_list

        #Adds an order to a list which is stored
        def add_order(self, order):
            self.order_list.append(order)
            print(f'[System Info] Added {order} to the order list: {self.order_list}')
        
        #Remove an order, once it's complete by the bartender
        def remove_order(self, complete_drink):
            self.order_list.remove(complete_drink)
            print(f'Drink {complete_drink} is complete!')
        
        #Print out the order_list
        def tell_bartender(self):
            print(f'Could you please make the following: {self.order_list}')

        #Prints a 'random' greeting phrase
        def welcome(self):
            greeting_phrases = ['Welcome', 'How are you today?', 'Hello!', 'Hey!']
            print(greeting_phrases[random.randint(0,3)])
        
        def serve(self, drink):
            print(f'Here is your {drink}. Hope it tastes well!')
        

    #Subclass Bartender
    class Bartender(Person):
        def __init__(self, name, age, speciality) -> None:
            super().__init__(name, age)
            self.speciality = speciality
        
        #Makes a specific drink, and removes that drink from the waiters order list using
        def make_drink(self, drink, this_waiter):
            this_waiter.remove_order(drink)
            this_waiter.serve(drink)
            Bar_Back.Bar.reduce_stock(drink, drink)

            print(f'[System Info] {drink} stock has been reduced! And is now saved!')
            
        
        #Buys more of a Liquor
        def buy_more(self, liquor):
            Bar_Back.liquor.stock += 100
            print(f'New stock of {Bar_Back.Liquor.name} is {Bar_Back.Liquor.stock}')

    #Create Bartender
    Max = Bartender('Max', 23, 'Whiskey Sour')

    #Create Guests
    Peter = Guest('Peter', 27, 0)

    #Create Waiter
    Jocke = Waiter('Jocke', 43, [])

    Name = input('Hello welcome! What is your name?')
    age = input('How old are you? ')
    Name = Guest(Name, int(age), None)

    if Name.age < 18:
        print('You are unfortunetly too young to be served here!')
        break

    elif Name.age >= 18:
        user_input = input('Would you like to see our menu? Y/N')
        if user_input == 'Y' or 'y':
            Name.ask_for_menu()

            decision = input('Have you decided what you would like? We also make phenomenal cocktails!')
            Jocke.add_order(decision)
            Max.make_drink(decision, Jocke)

            time.sleep(10)

            user_input = input('Would you like something more? Y/N')

            if user_input == 'N' or 'n':
                print('Okay thank you for this time!')
                break
                

        elif user_input == 'N' or 'n':
            print('Ok let me know if there is anything I can help you with then!')

Anyone knows why this is happening? The If else section is at the end of the code.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Instead of typing conditions like this:

if user_input == 'Y' or 'y':
            Name.ask_for_menu()

Type them like this:

if user_input == 'Y' or user_input == 'y':
            Name.ask_for_menu()

Make similar changes to all the conditions and your problem should be fixed

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading