Содержание:
Python Programming: Module 1 – Fundamentals
For English‑speaking students | Introduction to Input, Output, and Arithmetic
Laboratory Works (1.1 – 1.4)
Each lab includes an algorithm, solution code, and expected output. Click the solution to expand.
Task: Write a program that prints "Hello, World!" to the screen.
📌 Algorithm
- Call the built‑in
print()function. - Pass the string
"Hello, World!"as an argument. - The string is displayed when the program runs.
💡 Ready code
print("Hello, World!") |
📤 Expected Output
Hello, World!
Score 1.0
Task: Ask for the user’s name and print a personalised greeting.
📌 Algorithm
- Prompt with
input("Enter your name: ")and store inname. - Display
"Hello, " + name + "! Welcome to Python!".
💡 Ready code
name = input("Enter your name: ") print("Hello, ", name + "! Welcome to Python!") |
📤 Expected Output
Enter your name: Alice Hello, Alice! Welcome to Python!
Score 1.0
Task: Read two integers and print their sum.
📌 Algorithm
- Read first number via
input()and convert toint. - Read second number similarly.
- Add and store result.
- Print the sum.
💡 Ready code
num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: ")) sum_result = num1 + num2 print("Sum:", sum_result) |
📤 Expected Output
Enter first number: 5 Enter second number: 7 Sum: 12
⚠️ Common Pitfall: Forgetting int() will concatenate strings.
Score 1.0
Task: Read two numbers and print sum, difference, product, quotient.
📌 Algorithm
- Read two numbers as
float. - Compute sum, difference, product, quotient.
- Print each with labels.
💡 Ready code
a = float(input("Enter first number: ")) b = float(input("Enter second number: ")) print(a, "+", b, "=", a + b) print(a, "-", b, "=", a - b) print(a, "*", b, "=", a * b) print(a, "/", b, "=", a / b) |
📤 Expected Output
Enter first number: 10 Enter second number: 3 10 + 3 = 13 10 - 3 = 7 10 * 3 = 30 10 / 3 = 3.3333333333333335
📘 Exercises (5–10)
Additional exercises to reinforce the concepts. Score: 0.5 each. Click the solution to expand.
Score 0.5
Task: Print numbers 1, 2, 3 separated by » — » and ending with «!» on the same line.
📌 Algorithm
- Use
print()with arguments1, 2, 3. - Set
sep=" - "andend="!\n".
💡 Ready code
print(1, 2, 3, sep=" - ", end="!\n") |
📤 Expected Output
1 - 2 - 3!
Score 0.5
Task: Ask for first name, last name, and age, then display them in a formatted sentence.
💡 Ready code
first_name = input("Enter first name: ") last_name = input("Enter last name: ") age = input("Enter age: ") print("Hello,", first_name, last_name + "! You are", age, "years old.") |
📤 Expected Output
Enter first name: John Enter last name: Smith Enter age: 25 Hello, John Smith! You are 25 years old.
Score 0.5
Task: Read a three‑digit number and print its digits.
💡 Ready code
n = int(input("Enter a three-digit number: ")) last = n % 10 middle = (n // 10) % 10 first = n // 100 print("Digits:", first, middle, last) |
📤 Expected Output
Enter a three-digit number: 754 Digits: 7 5 4
Task: Convert Celsius to Fahrenheit: F = C * 9/5 + 32.
💡 Ready code
celsius = float(input("Enter temperature in Celsius: ")) fahrenheit = celsius * 9/5 + 32 print(celsius, "°C =", fahrenheit, "°F") |
📤 Expected Output
Enter temperature in Celsius: 25 25.0 °C = 77.0 °F
Task: Read length and width, calculate area and perimeter.
💡 Ready code
length = float(input("Enter length: ")) width = float(input("Enter width: ")) area = length * width perimeter = 2 * (length + width) print("Area:", area) print("Perimeter:", perimeter) |
📤 Expected Output
Enter length: 5 Enter width: 3 Area: 15.0 Perimeter: 16.0
Score 0.5
Task: Swap the values of two variables.
💡 Ready code
a = 5 b = 10 print("Before swap: a =", a, "b =", b) a, b = b, a print("After swap: a =", a, "b =", b) |
📤 Expected Output
Before swap: a = 5 b = 10 After swap: a = 10 b = 5
✏️ Practice Exercises (Independent Work)
Try these on your own. Each practice includes a hint. Score: 0.5 each. Click the solution to expand.
Score 0.5
Task: Print the following pattern:
**************** * Hello World * ****************
Hint: Use print() with * multiplication.
Score 0.5
Task: Ask for birth year and calculate age (current year = 2026).
Enter your birth year: 2000 You are 26 years old.
Hint: Use int() to convert input.
Score 0.5
Task: Read radius and calculate area using π = 3.14159.
Enter radius: 5 Area of circle: 78.53975
Hint: Area = π × r².
Score 0.5
Task: Convert Celsius to Fahrenheit with two decimal places.
Enter temperature in Celsius: 36.6 36.60°C = 97.88°F
Hint: Use float() and f‑strings for formatting.
Score 0.5
Task: Read a three‑digit number and calculate the sum and product of its digits.
Enter a three-digit number: 423 Sum of digits: 9 Product of digits: 24
Hint: Use % and // to extract digits.
Score 0.5
Task: Convert seconds into minutes and remaining seconds.
Enter seconds: 125 125 seconds = 2 minutes and 5 seconds
Hint: Use // for minutes and % for remaining seconds.
Score 0.5
Task: Store length = 12 and width = 8, calculate area and perimeter, then swap values and recalculate.
Original: length = 12, width = 8 Area: 96, Perimeter: 40 After swap: length = 8, width = 12 Area: 96, Perimeter: 40
Score 0.5
Task: Read three words and print them separated by » | » and ending with «.»
Enter word 1: Python Enter word 2: is Enter word 3: fun Python | is | fun.
Hint: Use sep and end parameters of print().
Score 0.5
Task: Read three numbers and calculate their average.
Enter first number: 4 Enter second number: 7 Enter third number: 10 Average: 7.0
Score 0.5
Task: Read a four‑digit number and print it in reverse order.
Enter a four-digit number: 1234 Reversed: 4321 Sum: 10
Hint: Extract each digit using % and //.