HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →
Live examsInternational live exams are comingTell us which exam you want first. Timed practice papers are open now.See what is coming →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Space Science and Astronomy
  • Earth and Environmental Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Python Programming
  2. /Python Basics
  3. /Input and Output

Input and Output

Python Programming · Middle Stage (6–8) · 2 courses, 21 worked problems, 36 practice questions

A program needs a way to talk to the person using it. In Python, print() shows text and numbers on the screen, and input() reads what the user types. The value from input() is always a string, so you change it to a number with int() or float() before doing arithmetic. An f-string such as f"Speed: {v} m/s" puts values into a sentence, and {v:.2f} shows a value to two decimal places. With these two functions, a script becomes a small interactive tool, such as a unit converter or a quiz.

With practice you will be able to

  • Read a number from the user with input() and float()
  • Print a result inside a sentence with an f-string
  • Round a printed value to a set number of decimal places

On the syllabus of

  • CBSE / State Class 12
  • Python Certification
  • AP
  • IB
  • A-Level
  • IGCSE

Lessons

  • Ask and Answer: input()Why can 3 plus 4 give 34? How do friends split a bill fairly?Middle Stage (6–8)
  • Say Hello to PythonWhen does print() work out a sum? What does an error message tell you?Middle Stage (6–8)

Practice questions

Choose an answer, then check it. Each one shows a full explanation.

A greeting program asks for a name and then for a number. The user types Ann, presses Enter, types 3 and presses Enter again. name = input() n = int(input()) print(name[0] * n, name + str(n), sep=":") What is shown on the screen?

The user types three numbers on one line, with a space between them: 4 2 9. The program cuts the line into pieces. nums = input().split() print(nums[0] + nums[-1], int(nums[0]) + int(nums[-1]), len(nums)) What does the program print?

A function asks a question with input() and a prompt. The user types 4 and presses Enter. def ask(prompt): reply = input(prompt) return reply * 2 print(ask("n? "), "end") Do not count the characters the user types. What text does the program itself write on the screen?

Worked problems

Each one has a hint, the key idea and a full worked solution.

  • A student wrote a program that asks for the price of an item…Medium
  • A program asks two questions. The Input box has these two lines: India and then Pune…Easy
  • Write a program that asks for the length and the width of a rectangle in centimetres, as numbers…Medium
  • Predict the outputEasy
  • Write a program that asks What is your name? …Easy

Python labs

  • Greet the user
  • Add two numbers
  • Age in ten years
  • Celsius to Fahrenheit
  • Project: the tip calculator
  • Project: the bill splitter

Related topics

  • Python Basics
  • Getting Started with Python
  • Variables and Data Types
  • Operators and Expressions
  • Strings
  • Conditionals: if, elif, else
  • Loops
  • Lists
  • Functions
  • Mini Projects

A function prints a value with its own end, and returns another value. Two calls are the arguments of one print() with sep. def tag(x): print(x, end="-") return x + 5 print(tag(1), tag(2), sep="|") What does the program print?

A program calls print() three times with keyword arguments, and then once with nothing. print("A" + "B", "C" * 2, sep=",", end="/") print(3, 4, sep="" + "-", end="") print("!", 5 + 5, end="") print() What does the program print?

A program reads two lines from the keyboard. The first line entered is 10 and the second line is 9. a = input() b = input() print(a > b, int(a) > int(b), max(a, b), a + b == "109") What does the program print?

A program has three input() lines, but the Input box has only two lines. What happens?

The user types 2.5. What does print(float(input()) * 2) show?

int() turns text into a number. What does print(int("7") * 3) show?

A program has age = int(input()), and the user types 12.5. What happens?

All 36 practice questions on Input and Output →

A program reads two numbers with a = input() and b = input(), then shows a + b…
Easy
  • Write a program that reads two whole numbers and shows their sum…Easy
  • Write a program that reads a temperature in degrees Celsius and shows it in degrees Fahrenheit…Medium
  • Ask for the user's age and show how old they will be in ten years.Easy
  • Write a program that reads the radius of a circle in centimetres and shows its area, with A = 3.14…Medium
  • Read three marks and show their average, rounded to two places…Medium
  • A bus travels at 60 km/h for 2.5 hours. Write a program that reads the speed and the time, and…Medium
  • All 21 worked problems on Input and Output →