The question is: "Write a program that will have the user enter words until the word "quit" is entered. Display the number that represents all the characters typed, with the exception of the last word, "quit".
Here, I am trying to write the code without using for/while loop. My code is:
def num():
summ = 0
inp = input ("Enter: ")
if inp != "quit":
for w in inp:
summ += 1
inp = input("Enter: ")
else:
return (summ)
print(num())
I am using Python 3.7. Even I am taking user input on line 9, still it is not accepting user input again and again, until the user writes "quit". May I please know why this is wrong? Can I write this program without using any loop? Thank you very much for helping me.
Aucun commentaire:
Enregistrer un commentaire