Reading input

while loops can have conditions that are always satisfied. Those programs will result in an infinite loop and will run forever. A good example of that type of program is while True:
while True:
    print('Welcome to an infinite loop!')
This program will run forever and will print Welcome to an infinite loop! until it’s stopped by the user.
while loops can be used to read data until some condition has been met. For instance, we can read the data from the input while the input is not 0. As soon as the user inputs a 0 and hits enter, the while loop should end. This can be implemented as:
num = -1
while num != 0:
    num = int(input())
    print(f'The user entered: {num}')
print('End!')
This program will read the input as long as the user hasn’t entered 0, and as soon as the user enters 0, it will get out of the loop and print End!.
 
We can even read the num beforehand and then start the loop:
num = int(input())
while num != 0:
    print(f'The user entered: {num}')
    num = int(input())
print('End!')
This way, the program won’t print the final 0 as it will get out of the loop before that.
You can try it yourself to play around with those two ways.

Challenge

Write a program that reads the input until reaching a word End and prints the inputted text to the output. As soon as the program reaches the word End it should stop. The program should not print the final End from the input.
Input
Output
hello my name End
hello my name
 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue