Count how many times a value was printed | SoloLearn: Learn to code for FREE!


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

11/3/2016 12:40:04 PM


3 Answers

New Answer


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


Counter = 0 #before while Counter += 1 #during while print(Counter) #after while


it works! thanks a lot for the answers