How to stop While Loop in python

Advertisements
def auction():
    end_of_auction = False
    while not end_of_auction:
        user = str(input('what is your name: '))
        bid = int(input('what is your bid? : $'))
        database = {user:bid}

        again = input('again ? (Yes or No) : ').lower
        if again == 'no':
            temp = 0
            for i in database:
                value = database[i]
                if value > temp:
                    temp = value
                database = {i:temp}  
            print(f'the winner is {i} and the bid is ${value}')
            break
        elif again == 'yes':
            end_of_auction = True

auction()

I have a problem with this while loop in my function, it never stop. I try to change the value of the variable end_of_auction but is dosen’t work. then I tried to use the keyword break but is dosen’t work.

can someone please tell me what is the problem here and how can I end the loop?

>Solution :

The issue is that you are not calling the lower() method; instead, you store the method itself to the variable again. You can see that if you call print(again), as you get something resembling <built-in method lower of str object at 0x000002525EEA8030>.

Change the line to:

again = input('again ? (Yes or No) : ').lower()

All you other code seems like it should function as intended.

Leave a ReplyCancel reply