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

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

11/3/2016 12:40:04 PM

Nelson20

3 Answers

New Answer

+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

+2

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

+1

it works! thanks a lot for the answers