+ 1

How can I create a "counter" program, using user input and for loop to increase/decrease a value?

I'm trying to write a "counter" program that'll increase a positive integer by 1 whenever the user enters "increase" and decrease the value by 1 when "decrease" is entered. I tried a while loop but as long as the expression says >= 0, it creates an endless loop. How do I use a for loop to write the program, such that the value only increases/decreases by 1?

12th Mar 2022, 10:13 AM
Kamdili Ife Darachukwu
Kamdili Ife Darachukwu - avatar
2 Antworten
+ 2
You may try something like this count = 0 while (cominp:= input()) in ["increase","decrease"]: if cominp == "increase": count += 1 else: count -= 1 print(count)
12th Mar 2022, 10:40 AM
Simba
Simba - avatar