0

Count how many times a value was printed

Hello, Could anyone help me with this program? Well I have to introduce a program using while like this answer= input ("Enter a word:) while answer !="exit" : print("Hello") answer=input ("Enter again:") and I was want to know how many times it print "Hello" before the user entered : "exit" for example it printed "Hello" five times before the user entered exit, it has to apoyar a message: "The word Hello was printed 5 times" Please help me

3rd Nov 2016, 12:40 PM
Nelson20
3 Respostas
+ 3
count = 0 while True: answer = input("Enter a word : ") if answer == "exit": break else: print ("Hello") count += 1 print ("Hello is printed ",count) This will do the job as you want to
3rd Nov 2016, 4:29 PM
Waqas Asghar Bhalli
Waqas Asghar Bhalli - avatar
+ 2
Counter = 0 #before while Counter += 1 #during while print(Counter) #after while
3rd Nov 2016, 12:51 PM
Pierre Drt
+ 1
it works! thanks a lot for the answers
3rd Nov 2016, 5:24 PM
Nelson20