Basics · Lesson 9 of 27
Taking input
input() reads one line typed by the user. It always gives a string, even if the user types a number.
name = input()
print(f"Hi {name}")To do maths, convert the string first:
int("5")→5float("2.5")→2.5str(5)→"5"
a = int(input()) b = int(input()) print(a + b)
If you forget int(), "3" + "4" gives "34", because strings are joined, not added!
In this course, type your input in the Input box under the editor, one value per line. In coding tests (and here), don't put a message inside input(). Just use input().
Your task
Read two whole numbers (each on its own line) and print their sum.
For input 3 and 4, the output should be 7.