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

Time:07-11

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

CodePudding user response:

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

CodePudding user response:

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()


  • Related