Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13981

Python while loop keeps asking endlessly for the same thing

$
0
0

I am trying to learn Python and I am still endlessly stuck with the same issue.In the exercise that I do, a user needs to insert coin of 5, 10 or 25 (nothing else) until he/ she reaches 50.

But when I run the script, I am always asked to insert a coin. Without being told what remains.

Here is my code:

amount_to_reach = 50    money = int(input("Insert coin"))    if money != 10 and money != 5 and money != 25:       print("Amount Due: 50")    else:       while money < 50:          money = money + int(input("Insert coin"))    print(f"Amount due: {money - amount_to_reach}") 

This is my output:

Insert coin 5Insert coin 5...Insert coin 5

Endlessly

Ok so here is the new version, which now works:

amount_to_reach = 50money = int(input("Insert coin"))if money != 10 and money != 5 and money != 25:   print("Amount Due: 50")else:   while money < 50:      money = money + int(input("Insert coin"))      print(f"Amount due: {money - amount_to_reach}")print(f"Change Owed: {money - amount_to_reach}")

Viewing all articles
Browse latest Browse all 13981

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>