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

How to stop While Loop in python

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?

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 :

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.

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