Python · Python Fundamentals

Variables, Data Types & Input/Output: Practice Questions

100 questions. Try each one yourself before checking the answer.

Short on time? Filter by Must Do for the 25 questions that cover this topic on their own.

Q1print()EasyMust Do

Print the exact text Hello, World! to the screen.

Q2print()Easy

Print your own name, then on the next line print your favourite colour. Use two separate print() statements.

Q3print()Easy

Print the three words Python, is, and fun using a single print() with commas between them. Notice that Python puts a space between each one for you.

Q4print()Easy

Print a blank line between the words Top and Bottom, using an empty print().

Q5print()Easy

Print Python, is, and fun joined by a dash instead of a space, like Python-is-fun. Use the sep setting of print().

Q6print()Easy

Normally each print() starts a new line. Print Hello and World from two separate print() statements but make them appear on the same line, using the end setting.

Q7Escape SequencesEasyMust Do

Print Line one and Line two on two separate lines using one print() and the newline escape sequence \n.

Q8Escape SequencesEasy

Print Name and Age separated by a tab, using the escape sequence \t.

Q9Escape SequencesEasy

Print the sentence She said "hello" to me. — including the double quotes around hello. Do it two ways: once with single quotes around the whole string, and once using \".

Q10Escape SequencesEasy

Print a Windows-style file path exactly as C:\Users\Asha. A single backslash has a special meaning, so you need \\ for each one.

Q11print()Easy

Print a three-line poem using one print() and a triple-quoted string ("""). The line breaks you type inside the quotes are kept exactly as written.

Q12print()Easy

Print a line of exactly 20 equals signs (====================) without typing them all out. Multiply the string by a number.

Q13print()Easy

Print Good morning! by joining the two pieces "Good " and "morning!" with the + sign.

Q14VariablesEasyMust Do

Create a variable called age, store the number 25 in it, and print it.

Q15VariablesEasy

Create a variable score holding 10. Print it. Then store 20 in the same variable and print it again — a variable keeps only its most recent value.

Q16VariablesEasy

Create a variable city holding the text "Mumbai" and print it. Text values must be wrapped in quotes; numbers must not.

Q17VariablesEasyMust Do

Create first_name and last_name, then print a greeting like Hello, John Doe! by joining the pieces with +. Remember to include the space between the names.

Q18CommentsEasyMust Do

Write a program that prints 2 + 3 = 5, with a comment above the line explaining what it does. Comments start with # and Python ignores them completely.

Q19CommentsEasy

Store 5 in a variable side and print it, with an inline comment at the end of the assignment line saying what side means.

Q20CommentsEasy

Write a three-line block comment at the top of a program describing what it does, then print Ready. Each line of a block comment needs its own #.

Q21Data TypesEasyMust Do

Store the whole number 7 in a variable and print both the value and its type using type(). Whole numbers are called int.

Q22Data TypesEasy

Store the decimal number 19.99 in a variable and print its type. Numbers with a decimal point are called float.

Q23Data TypesEasy

Store the text "Alice" in a variable and print its type. Text is called str, short for string.

Q24Data TypesEasyMust Do

Store True in a variable and print its type. True and False are the only two bool values, and both start with a capital letter.

Q25NoneEasyMust Do

Store None in a variable called result and print both the value and its type. None is Python's way of saying "no value yet".

Q26Naming ConventionsEasyMust Do

These three names are all illegal in Python: 2cool, my-variable, class. Rewrite each as a valid snake_case name, give it a value, and print all three.

Q27Naming ConventionsEasy

Create a variable total_marks holding 450. Then try printing Total_Marks and explain in a comment why Python complains.

Q28Naming ConventionsEasy

Python has no real constants, but by convention a value that should never change is named in ALL_CAPS. Create PI = 3.14159 and MAX_USERS = 100 and print both.

Q29VariablesEasy

Assign 1, 2 and 3 to the variables a, b and c on a single line, then print all three.

Q30VariablesEasy

Set three variables x, y and z all to 0 in one line, using chained assignment, and print them.

Q31VariablesMedium

Create x = 5 and y = 10, then swap their values without using a third variable, and print both.

Q32VariablesMedium

Start with score = 10. Add 5 to it using the shortcut += instead of writing score = score + 5, then print the result.

Q33VariablesMedium

Start with balance = 100. Subtract 30 with -=, then double it with *=, then halve it with /=, printing after each step.

Q34input()MediumMust Do

Ask the user for their name and print Welcome, <name>!.

Q35input()MediumMust Do

Ask the user to type a number, then print the type of what you received. Explain the result in a comment.

Q36Type ConversionMediumMust Do

Ask the user for a whole number, convert it with int(), add 10, and print the answer.

Q37Type ConversionMedium

Ask the user for a price as a decimal, convert it with float(), and print double the price.

Q38input()Medium

Ask the user for two numbers on two separate lines, then print their sum.

Q39Type ConversionMedium

Given score = 90 (an int), build the message "Your score: 90" using +. You will need str() to make this work.

Q40Type ConversionMedium

Convert the float 9.87 to an int and print it. Note in a comment that Python chops the decimal off rather than rounding.

Q41Type ConversionMedium

Convert the integer 7 to a float and print both the value and its type.

Q42Type ConversionMedium

Print bool() applied to each of 0, 1, -5, "", "hello", 0.0. Then describe the pattern in a comment.

Q43Type ConversionMedium

Add an int and a float together. Print the result and its type, then explain in a comment which type Python picked and why.

Q44f-stringsMediumMust Do

Create city = "Pune" and print I live in Pune. using an f-string. An f-string is a normal string with f in front, letting you drop variables straight into {}.

Q45f-stringsMedium

Create name, age and country, then print one sentence containing all three using a single f-string.

Q46f-stringsMedium

Given a = 7 and b = 3, print 7 + 3 = 10 using one f-string. You can put a calculation directly inside the {}.

Q47f-stringsMediumMust Do

Print pi = 3.14159265 rounded to exactly 2 decimal places using an f-string.

Q48f-stringsMedium

Print the number 42 right-aligned in a column 10 characters wide, so it sits at the far right.

Q49f-stringsMedium

Print the word Hi three times in a 10-wide column: once left-aligned (<), once centred (^), once right-aligned (>). Add a | after each so you can see the column edge.

Q50f-stringsMedium

Print the word SALE centred in a 20-wide field, padded with * on both sides instead of spaces.

Q51Real-WorldMediumMust Do

Ask for the length and width of a rectangle and print its area to 2 decimal places.

Q52Real-WorldMedium

Extend the last idea: ask for length and width, then print both the area and the perimeter on separate lines, each to 2 decimal places.

Q53Real-WorldMedium

Ask for the radius of a circle and print its area using PI = 3.14159, to 2 decimal places.

Q54Real-WorldMedium

Write a simple-interest calculator. Ask for principal, rate (%) and time (years), compute principal * rate * time / 100, and print the interest to 2 decimal places.

Q55Real-WorldMediumMust Do

Convert a temperature from Celsius to Fahrenheit using F = C * 9 / 5 + 32. Take Celsius as input and print the result to 1 decimal place.

Q56Real-WorldMedium

Now go the other way: convert Fahrenheit to Celsius using C = (F - 32) * 5 / 9, printing to 1 decimal place.

Q57Real-WorldMedium

Ask for the price of one item and how many were bought, then print the total bill as currency, e.g. Total: $49.50.

Q58Real-WorldMediumMust Do

Ask for three exam scores and print their average to 1 decimal place.

Q59Real-WorldMedium

Ask for marks obtained and total marks, then print the percentage to 2 decimal places.

Q60Real-WorldMedium

Write a tip calculator. Ask for the bill amount and tip percent, then print the tip and the final total, both as currency.

Q61Real-WorldMedium

Ask for an item's original price and a discount percent, then print the amount saved and the final price.

Q62Real-WorldMedium

Ask for a distance in kilometres and print it in miles, to 2 decimal places (1 km = 0.621371 miles).

Q63Real-WorldMedium

Ask for a weight in kilograms and print it in pounds and grams, each to 2 decimal places (1 kg = 2.20462 lb = 1000 g).

Q64Real-WorldMediumMust Do

Write a BMI calculator. Ask for weight in kg and height in metres, compute weight / (height * height), and print the BMI to 1 decimal place.

Q65Real-WorldMedium

Ask for a distance in km and a time in hours, then print the average speed in km/h to 2 decimal places.

Q66FormattingMedium

Print the number 2500000 with comma thousands-separators, so it reads 2,500,000.

Q67FormattingMedium

Given fraction = 0.4567, print it as a percentage with 1 decimal place (45.7%) using a format specifier — do not multiply by 100 yourself.

Q68FormattingMediumMust Do

Print one receipt line: the item name left-aligned in 15 characters, and the price right-aligned in 10 characters with 2 decimals. Aim for Notebook 45.50.

Q69FormattingMedium

Ask for a single word and print it centred in a 20-wide banner made of - characters, with the word's length underneath.

Q70Real-WorldMedium

Ask for a bill total and the number of people sharing it, then print the amount each person owes as currency.

Q71Type ConversionHardMust Do

int("3.9") crashes with a ValueError. Show why, then convert the string "3.9" to an int correctly and print the result.

Q72Type ConversionHard

Print round(2.5) and round(3.5). One of them does not do what you expect. Print both and explain the behaviour in a comment.

Q73Data TypesHardMust Do

Print the result of 0.1 + 0.2 and then compare it to 0.3. Explain the surprising output in a comment.

Q74Data TypesHard

Print type(True) and isinstance(True, int), then print True + True. Explain why a bool behaves like a number.

Q75Data TypesHard

Given value = 10, show the difference between type(value) == int and isinstance(value, int), and note in a comment which one is generally preferred.

Q76FormattingHard

Print the number 255 in binary, octal and hexadecimal using only f-string format specifiers (b, o, x) — without bin(), oct() or hex().

Q77FormattingHard

Print 93500000.0 in scientific notation with 2 decimal places, using a format specifier.

Q78FormattingHard

Print a profit of 250.0 and a loss of -120.5 so that the sign is always shown (+250.00 and -120.50), to 2 decimal places.

Q79FormattingHard

Print 1234567.891 as currency with both thousands-separators and 2 decimals, right-aligned in a 20-wide field, like $1,234,567.89.

Q80DebuggingHard

Given total = 17.5, print total=17.5 using the f-string = specifier, which prints the variable's name and value together. Explain why this is useful when debugging.

Q81DebuggingHard

This code crashes with a TypeError. Explain the cause and fix it.

age = 20
message = "I am " + age + " years old"
print(message)
Q82DebuggingHard

This is meant to print My name is Sam but prints My name is {name} instead. Find and fix the bug.

name = "Sam"
print("My name is {name}")
Q83DebuggingHard

This raises a NameError. Find and fix it.

username = "coder123"
print(User_name)
Q84DebuggingHardMust Do

This crashes when it tries to add 10. Explain why and fix it.

number = input("Enter a number: ")
result = number + 10
print(result)
Q85DebuggingHard

This snippet has three separate bugs: an unterminated string, a missing type conversion, and a name used with the wrong capitalisation. Find and fix all three.

Price = input("Enter price: )
total = price * 3
print("Total: " + total)
Q86Mini-ProjectMini-ProjectMust Do

Build a Personal Profile Card. Ask for name, age, city and email, then print a bordered card:

==============================
 Name : Asha
 Age  : 22
 City : Pune
 Email: asha@example.com
==============================
Q87Mini-ProjectMini-Project

Build a Length Unit Converter. Ask for a length in metres and print the equivalent in centimetres, feet and inches, each to 2 decimal places, in aligned columns. (1 m = 100 cm = 3.28084 ft = 39.3701 in)

Q88Mini-ProjectMini-Project

Build an Invoice Generator for one item. Ask for item name, quantity and unit price, then print aligned columns with the total:

Item                Qty   Unit Price   Total
Notebook            3     45.50        136.50
Q89Mini-ProjectMini-ProjectMust Do

Build a Student Report Card. Ask for the student's name and marks in three subjects, then print a bordered card showing each subject's mark, the total, and the percentage to 2 decimal places.

Q90Mini-ProjectMini-Project

Build a Shopping Bill for one item. Ask for the item name, unit price, quantity, discount percent and tax percent. Print the subtotal, discount, taxed amount and final payable, all aligned as currency.

Q91Mini-ProjectMini-Project

Build a Salary Slip. Ask for the employee's name and basic salary. Compute HRA as 20% of basic, DA as 10% of basic, tax as 15% of basic, and net pay as basic + HRA + DA - tax. Print an aligned slip.

Q92Mini-ProjectMini-Project

Build a Time Breakdown display. Ask for a duration in total hours as a decimal (e.g. 2.75) and print it as hours and minutes (2 hours 45 minutes). Use int() to separate the whole hours from the fraction.

Q93Mini-ProjectMini-Project

Build a Circle Fact Sheet. Ask for a radius and print the diameter, circumference and area, each to 3 decimal places and right-aligned in a column.

Q94Mini-ProjectMini-Project

Build a Type Conversion Report. Ask for one value, then print a table showing it converted to float, int (via float first), bool and str, alongside the type() of each result.

Q95Mini-ProjectMini-Project

Build an Escape Sequence Showcase: a single program that demonstrates \n, \t, \", \\ and a triple-quoted block, each with a printed label saying which one it is.

Q96InterviewInterview

Python is dynamically typed — a variable's type can change while the program runs. Demonstrate it: point one variable at an int, then a str, then a float, printing the value and type each time.

Q97InterviewInterview

Given a = 5 (an int) and b = "5" (a str), show why a == b is False while a == int(b) is True.

Q98InterviewInterview

Given value = 8342.567, print it four ways using only f-string format specifiers: as currency with commas, as a percentage, in scientific notation, and rounded to a whole number.

Q99InterviewInterview

Simulate an ATM Withdrawal Receipt. Ask for the account holder's name, current balance and withdrawal amount. Print a receipt showing the holder, the amount withdrawn and the new balance, with all currency aligned to 2 decimal places.

Q100CapstoneInterviewMust Do

Build a Variable Inspector — the single most complete demonstration of this whole topic. Ask for one value, then print a labelled, aligned report showing: the raw text and its type, its length, the value as a float, as an int, as a bool, and the float shown to 2 decimal places, in scientific notation, and as a percentage.

Still stuck on something?

Book a free 1-on-1 session and we'll work through it together.

Book a Free Session