Python Input Practice Questions for Beginners
Chapter 7 Recap and Practice
Your programs can now listen to the user. Here is the chapter in one table:
| You write | It does |
|---|---|
name = input() | reads one line the user types, as text |
input("Name: ") | shows a prompt first (it's printed into the output) |
two input() calls | read two lines, in order; too few lines gives EOFError |
int(input()) | reads a whole number |
float(input()) | reads a number that may have decimals |
int("2.5"), int("ten") | ValueError: the text isn't a whole number |
| input, process, output | read the values, work with them, show the result |
On LivePython, type the answers in the Input box before the code runs, one per line.
Practice questions
In every question, use input() with no prompt text. The tests type several different inputs for you, so a program that only prints one fixed answer won't pass.
input()
- 51.Python Program to Greet the User by NameEasySolve
- 52.Python Program to Read Two Words and Make a SentenceEasySolve
Converting input
- 53.Python Program to Add Two Numbers from InputEasySolve
- 54.Python Program to Find a Rectangle's Area from InputEasySolve
- 55.Python Program to Convert Celsius to Fahrenheit from InputMediumSolve
Interactive programs
- 56.Python Program to Calculate Age in MonthsEasySolve
- 57.Python Program to Split a Bill Between FriendsMediumSolve
- 58.Python Program to Make a Shopping Receipt from InputHardSolve
Input, process, output: now your programs work for any user. Next, they'll make decisions with if.