w3resource

Python Exercise: Sequence of lines as input and prints the lines as output in lower case

Python Conditional: Exercise-12 with Solution

Write a Python program that accepts a sequence of lines (blank line to terminate) as input and prints the lines as output (all characters in lower case).

Pictorial Presentation:

Python Exercise: Sequence of lines as input and prints the lines as output in lower case

Sample Solution:

Python Code:

# Create an empty list named 'lines'
lines = []

# Continue to prompt the user for input indefinitely until a blank line is entered
while True:
    # Prompt the user to input a line of text
    l = input()
    
    # Check if the entered line is not empty (non-empty string)
    if l:
        # Convert the entered line to uppercase and append it to the 'lines' list
        lines.append(l.upper())
    else:
        # If the entered line is empty, break out of the loop
        break;

# Iterate through each line in the 'lines' list
for l in lines:
    # Print each line (converted to uppercase) from the 'lines' list
    print(l) 
	

Sample Output:

w3resource                                                                                                    
Python                                                                                                        
                                                                                                              
W3RESOURCE                                                                                                    
PYTHON

Flowchart:

Flowchart: Python - Sequence of lines as input and prints the lines as output in lower case

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program which takes two digits m (row) and n (column) as input and generates a two-dimensional array. The element value in the i-th row and j-th column of the array should be i*j.
Next: Write a Python program which accepts a sequence of comma separated 4 digit binary numbers as its input and print the numbers that are divisible by 5 in a comma separated sequence.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://198.211.115.131/python-exercises/python-conditional-exercise-12.php