Python Programming, Module 1 – Fundamentals. Input, Output, and Arithmetic




Python Programming: Module 1 – Fundamentals. Input, Output, and Arithmetic.

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.

Example 1: Lab 1.1 – Hello, World! Score 1.0

Task: Write a program that prints "Hello, World!" to the screen.

📌 Algorithm

  1. Call the built‑in print() function.
  2. Pass the string "Hello, World!" as an argument.
  3. The string is displayed when the program runs.
💡 Ready code
print("Hello, World!")

📤 Expected Output

Hello, World!

Task 2: Lab 1.2 – Personalised Greeting
Score 1.0

Task: Ask for the user’s name and print a personalised greeting.

📌 Algorithm

  1. Prompt with input("Enter your name: ") and store in name.
  2. 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!

Task 3: Lab 1.3 – Sum of Two Numbers
Score 1.0

Task: Read two integers and print their sum.

📌 Algorithm

  1. Read first number via input() and convert to int.
  2. Read second number similarly.
  3. Add and store result.
  4. 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.

Task 4: Lab 1.4 – Arithmetic Operations
Score 1.0

Task: Read two numbers and print sum, difference, product, quotient.

📌 Algorithm

  1. Read two numbers as float.
  2. Compute sum, difference, product, quotient.
  3. 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.

Task 5: Using sep and end
Score 0.5

Task: Print numbers 1, 2, 3 separated by » — » and ending with «!» on the same line.

📌 Algorithm

  1. Use print() with arguments 1, 2, 3.
  2. Set sep=" - " and end="!\n".
💡 Ready code
print(1, 2, 3, sep=" - ", end="!\n")

📤 Expected Output

1 - 2 - 3!

Task 6: Personal Information
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.

Task 7: Extracting Digits
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

Task 8: Swapping Variables
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.

Practice 1: Simple Greeting
Score 0.5

Task: Print the following pattern:

****************
*  Hello World  *
****************

Hint: Use print() with * multiplication.

Practice 2: Age Calculator
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.

Practice 3: Area of a Circle
Score 0.5

Task: Read radius and calculate area using π = 3.14159.

Enter radius: 5
Area of circle: 78.53975

Hint: Area = π × r².

Practice 4: Celsius to Fahrenheit (with Decimals)
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.

Practice 5: Sum and Product of Digits
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.

Practice 6: Seconds to Minutes and Seconds
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.

Practice 7: Rectangle Area and Perimeter (with Variables)
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

Practice 8: Custom Separator
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().

Practice 9: Average of Three Numbers
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

Practice 10: Number Reversal and Sum
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 //.