Reading Input

Reading input: input, int(input()) and map for several numbers on one line.

In problems the data arrives on standard input. In Python a line is read by the input() function. Important: input() always returns a string. To get a number you must convert the string: int(input()) for an integer, float(input()) for a float. Forgetting the int is the most common beginner mistake: the program will glue "3" and "5" into "35" instead of adding 3 + 5. Press "Input" above the code, enter a number and run it.
Python

Enter a number in the "Input" field, for example: 7

When one line contains several numbers separated by spaces, use the split-and-map combo: • input().split() — splits the line into parts by whitespace; • map(int, ...) — turns every part into a number. You will write this line in every other problem — memorize it like a formula.
Python

Enter two numbers separated by a space, for example: 3 5

Task: read three numbers from one line and print their arithmetic mean. The main practice is the attached problem "Sum of Two Numbers": solve it, get the Accepted verdict and mark the lesson as completed.

Practice problems

Доска