Skip to main content
Anime study buddy

Learning outcomes

By the end of this chapter, you should be able to:
  • use input() for user input
  • convert input into required data type
  • take multiple values in one line
  • print clean output using formatting

Basic input

name = input("Enter your name: ")
print("Hello", name)
Important: input() always returns a string.

Numeric input with conversion

age = int(input("Enter age: "))
height = float(input("Enter height in meters: "))
Use:
  • int() for integers
  • float() for decimals

Multiple inputs in one line

a, b = input("Enter two numbers: ").split()
a = int(a)
b = int(b)
print(a + b)
Short form:
a, b = map(int, input("Enter two numbers: ").split())
print(a + b)

Output formatting

name = "Dhruv"
marks = 87
print(f"{name} scored {marks} marks")
f"..." formatting is clean and exam-safe.

Common mistakes

  • forgetting type conversion after input()
  • using + between string and integer
  • expecting input() to return int automatically

Exam-focused points

  • default return type of input() is str
  • type conversion functions: int(), float(), str()
  • split() returns a list of strings

Practice questions

  1. Take length and breadth as input and print area.
  2. Take 3 marks and print total and average.
  3. Write program to input name, class, and roll number and print in one formatted line.