Take some inputs until 0 encountered, print each word in lowercase and break the loop

Question:

Write a program to input the lines of text, print them to the screen after converting them to lowercase. The last line prints the number of input lines.

The program stops when it encounters a line with only zero.

Requirements: use infinite loop and break . statement

here’s my code but it’s saying Input 9 is empty

a = 1
l = 0
while a != 0:
    a = input()
    a.lower()
    print(a)
    l+=1

example inputs

TbH
Rn
ngL
bRb
0
Asked By: Meno

||

Answers:

There a few errors in your original code, here is some suggestions and fixes. This post is try to follow your code as much as it can, and point the changes needed.

Please see the comments and ask if you have any questions.

count = 0                   # to count the lines
while w != '0':             # input's string  
    w = input().strip()     # get rid of n space
    word = w.lower()        # convert to lower case
    
    print(word)
    count += 1
    #   while-loop stops once see '0' 

Outputs: (while running)

ABBA
abba
Misssissippi
misssissippi
To-Do
to-do
0
0
Answered By: Daniel Hao

This may accomplish what you are trying to achieve:


def infinite_loop():
    while True:
        user_input = input('enter a value:n> ')
        if user_input == '0':
            break
        else:
            print(user_input.lower())


if __name__ == '__main__':
    infinite_loop()


Answered By: Seraph

I’d suggest this, it’s a combination of these 2 comments, sorry

count = 0
while True:
        a = input()
        if a == '0':
            break
        else:
            print(a.lower())
        count += 1
print(count)
Answered By: yeet
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.