Skip to main content
EDU-MMCS
You are currently using guest access (Log in)

Basics of programming (Python)

  1. Home
  2. Courses
  3. Осенний семестр
  4. Python Eng
  5. Module 1
  6. Python Programming: Module 1 – Fundamentals

Python Programming: Module 1 – Fundamentals

Python Programming: Module 1 – Fundamentals

🐍 Python Programming: Module 1 – Fundamentals

For English‑speaking students  |  Introduction to Input, Output, and Arithmetic

📑 Table of Contents

  • 🔹 Laboratory Works 1.1 – 1.4
  • 🔸 Exercises 5–10
  • 🔹 Practice Exercises
  • 🔸 Answer Key

🧪 Laboratory Works (1.1 – 1.4)

Each lab assignment includes a step‑by‑step algorithm, solution code, and expected output. Max score: 1.0 per lab.

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 on the screen when the program runs.

💻 Solution Code


print("Hello, World!")
                

📤 Expected Output

Hello, World!
📖 Step‑by‑Step Explanation
  1. print() is a built‑in function that displays output.
  2. The text inside quotes "Hello, World!" is a string.
  3. When you run the program, the text appears on the screen.

Lab 1.2 – Personalised Greeting

Score: 1.0

Task: Write a program that asks for the user's name and prints a personalised greeting.

📌 Algorithm

  1. Prompt the user with input("Enter your name: ") and store the result in a variable name.
  2. Use print() to display "Hello, " + name + "! Welcome to Python!".
  3. Alternatively, use an f‑string (later topic).

💻 Solution Code


name = input("Enter your name: ")
print("Hello, ", name + "! Welcome to Python!")
                

📤 Expected Output (example)

Enter your name: Alice
Hello, Alice! Welcome to Python!
📖 Step‑by‑Step Explanation
  1. input("Enter your name: ") displays the prompt and waits for user input.
  2. The entered text is stored in the variable name.
  3. print() displays the greeting with the user's name.
  4. The + operator concatenates (joins) strings.

Lab 1.3 – Sum of Two Numbers

Score: 1.0

Task: Write a program that reads two integers from the user and prints their sum.

📌 Algorithm

  1. Read the first number using input() and convert to int.
  2. Read the second number similarly.
  3. Add the two numbers and store the result.
  4. Print the sum.

💻 Solution Code


num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
sum_result = num1 + num2
print("Sum:", sum_result)
                

📤 Expected Output (example)

Enter first number: 5
Enter second number: 7
Sum: 12
📖 Step‑by‑Step Explanation
  1. input() reads a string from the user.
  2. int() converts the string to an integer.
  3. The two numbers are stored in num1 and num2.
  4. num1 + num2 calculates the sum.
  5. The result is stored in sum_result and printed.

⚠️ Common Pitfall: Forgetting to convert with int() will concatenate strings instead of adding numbers.

Lab 1.4 – Arithmetic Operations

Score: 1.0

Task: Write a program that reads two numbers and prints their sum, difference, product, and quotient.

📌 Algorithm

  1. Read two numbers as float to allow decimals.
  2. Compute sum, difference, product, and quotient.
  3. Print each result with appropriate labels.

💻 Solution 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 (example)

Enter first number: 10
Enter second number: 3
10 + 3 = 13
10 - 3 = 7
10 * 3 = 30
10 / 3 = 3.3333333333333335
📖 Step‑by‑Step Explanation
  1. float() is used to handle decimal numbers.
  2. Each arithmetic operation is performed and printed.
  3. print() with multiple arguments automatically adds spaces between them.

📘 Exercises (5–10)

Additional exercises to reinforce the concepts. Score: 0.5 each.

Exercise 5 – Using sep and end

Score: 0.5

Task: Write a program that prints the numbers 1, 2, 3 separated by " - " and ends with "!" on the same line.

📌 Algorithm

  1. Use print() with multiple arguments 1, 2, 3.
  2. Set sep=" - " to change the separator.
  3. Set end="!\n" to append "!" and a newline.

💻 Code

print(1, 2, 3, sep=" - ", end="!\n")

📤 Expected Output

1 - 2 - 3!

Exercise 6 – Personal Information

Score: 0.5

Task: Ask for first name, last name, and age, then display them in a formatted sentence.

📌 Algorithm

  1. Collect first name, last name, and age using input().
  2. Print the sentence using multiple arguments or concatenation.

💻 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 (example)

Enter first name: John
Enter last name: Smith
Enter age: 25
Hello, John Smith! You are 25 years old.

Exercise 7 – Extracting Digits

Score: 0.5

Task: Read a three‑digit number and print its digits in reverse order.

📌 Algorithm

  1. Read the number as integer.
  2. Extract last digit: n % 10.
  3. Extract middle digit: (n // 10) % 10.
  4. Extract first digit: n // 100.
  5. Print digits in reverse order.

💻 Code

n = int(input("Enter a three-digit number: "))
last = n % 10
middle = (n // 10) % 10
first = n // 100
print("Digits in reverse:", last, middle, first)

📤 Expected Output (example)

Enter a three-digit number: 754
Digits in reverse: 4 5 7

Exercise 8 – Temperature Converter

Score: 0.5

Task: Convert Celsius to Fahrenheit using the formula: F = C * 9/5 + 32.

📌 Algorithm

  1. Read temperature in Celsius as float.
  2. Apply the formula.
  3. Print both temperatures with degree symbols.

💻 Code

celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = celsius * 9/5 + 32
print(celsius, "°C =", fahrenheit, "°F")

📤 Expected Output (example)

Enter temperature in Celsius: 25
25.0 °C = 77.0 °F

Exercise 9 – Rectangle Area and Perimeter

Score: 0.5

Task: Read length and width, calculate area and perimeter.

📌 Algorithm

  1. Read length and width as float.
  2. Area = length × width.
  3. Perimeter = 2 × (length + width).
  4. Print the results.

💻 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 (example)

Enter length: 5
Enter width: 3
Area: 15.0
Perimeter: 16.0

Exercise 10 – Swapping Variables

Score: 0.5

Task: Swap the values of two variables.

📌 Algorithm (using temporary variable)

  1. Store original value of a in temp.
  2. Assign b to a.
  3. Assign temp to b.

💻 Code (Pythonic swap)

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.

Practice 1 – Simple Greeting

Score: 0.5

Task: Print the following pattern:

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

Hint: Use print() with * multiplication.

📖 Algorithm
  1. Print a line of 16 asterisks.
  2. Print a line with "* Hello World *".
  3. Print another line of 16 asterisks.

📤 Expected Output

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

Practice 2 – Age Calculator

Score: 0.5

Task: Ask for birth year and calculate age (assume current year = 2026).

Enter your birth year: 2000
You are 26 years old.

Hint: Use int() to convert input.

📖 Algorithm
  1. Read birth year as integer.
  2. Set current year = 2026.
  3. Age = current year − birth year.
  4. Print the age.

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².

📖 Algorithm
  1. Read radius as float.
  2. Compute area = 3.14159 * radius ** 2.
  3. Print the area.

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.

📖 Algorithm
  1. Read Celsius as float.
  2. Apply formula: F = C * 9/5 + 32.
  3. Print both values formatted to 2 decimal places.

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.

📖 Algorithm
  1. Extract hundreds, tens, and units.
  2. Sum = d1 + d2 + d3.
  3. Product = d1 * d2 * d3.
  4. Print both.

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.

📖 Algorithm
  1. Read total seconds as integer.
  2. Minutes = total // 60.
  3. Remaining = total % 60.
  4. Print the result.

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
📖 Algorithm
  1. Initialize length = 12, width = 8.
  2. Compute and print area, perimeter.
  3. Swap values (e.g., using tuple unpacking).
  4. Recalculate and print again.

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().

📖 Algorithm
  1. Read three words using input().
  2. Print all three with sep=" | " and end=".".

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
📖 Algorithm
  1. Read three numbers as float.
  2. Average = (num1 + num2 + num3) / 3.
  3. Print the average.

Practice 10 – Number Reversal

Score: 0.5

Task: Read a four‑digit number and print it in reverse order.

Enter a four-digit number: 1234
Reversed: 4321

Hint: Extract each digit using % and //.

📖 Algorithm
  1. Extract units, tens, hundreds, thousands.
  2. Reversed = thousands*1000 + hundreds*100 + tens*10 + units.
  3. Print the reversed number.

🔑 Answer Key – Practice Exercises

Solutions for the independent practice exercises. Check your work after attempting them.

Practice 1 – Solution

print("*" * 16)
print("*  Hello World  *")
print("*" * 16)

Practice 2 – Solution

birth_year = int(input("Enter your birth year: "))
current_year = 2026
age = current_year - birth_year
print("You are", age, "years old.")

Practice 3 – Solution

radius = float(input("Enter radius: "))
pi = 3.14159
area = pi * radius ** 2
print("Area of circle:", area)

Practice 4 – Solution

celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = celsius * 9/5 + 32
print(f"{celsius:.2f}°C = {fahrenheit:.2f}°F")

Practice 5 – Solution

n = int(input("Enter a three-digit number: "))
d1 = n // 100
d2 = (n // 10) % 10
d3 = n % 10
print("Sum of digits:", d1 + d2 + d3)
print("Product of digits:", d1 * d2 * d3)

Practice 6 – Solution

seconds = int(input("Enter seconds: "))
minutes = seconds // 60
remaining = seconds % 60
print(seconds, "seconds =", minutes, "minutes and", remaining, "seconds")

Practice 7 – Solution

length = 12
width = 8
area = length * width
perimeter = 2 * (length + width)
print("Original: length =", length, "width =", width)
print("Area:", area, "Perimeter:", perimeter)
length, width = width, length
area = length * width
perimeter = 2 * (length + width)
print("After swap: length =", length, "width =", width)
print("Area:", area, "Perimeter:", perimeter)

Practice 8 – Solution

word1 = input("Enter word 1: ")
word2 = input("Enter word 2: ")
word3 = input("Enter word 3: ")
print(word1, word2, word3, sep=" | ", end=".")

Practice 9 – Solution

num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
average = (num1 + num2 + num3) / 3
print("Average:", average)

Practice 10 – Solution

n = int(input("Enter a four-digit number: "))
d4 = n % 10
d3 = (n // 10) % 10
d2 = (n // 100) % 10
d1 = n // 1000
print("Reversed:", d4 * 1000 + d3 * 100 + d2 * 10 + d1)

© 2026 Python Module 1 – All materials for educational use.  |  Happy Coding!

Skip Navigation
Navigation
  • Home

    • Site pages

      • My courses

      • Tags

    • My courses

    • Courses

      • Осенний семестр

        • Прикладная математика и информатика

        • Фундаментальная информатика и ИТ

        • Математика, механика

        • Педагогическое образование

        • Магистратура

          • Разработка мобильных приложений и компьютерных игр

        • Аспирантура

        • Вечернее отделение

        • Другое

        • Python Eng

          • Module 1

            • AssignmentPython Programming: Module 1 – Fundamentals

          • Topic 2

          • Topic 3

          • Topic 4

          • Topic 5

          • Topic 6

          • Topic 7

          • Topic 8

          • Topic 9

          • Topic 10

        • Экзамен ИКТ

        • ТестИИ

        • Информатика-Осень-ПМИ-2

        • Информатика-осень-ПМИ-1

        • ИММвс

      • Весенний семестр

        • Прикладная математика и информатика

        • Фундаментальная информатика и ИТ

        • Математика, механика

        • Педагогическое образование

        • Магистратура

          • Разработка мобильных приложений и компьютерных игр

        • Аспирантура

        • Вечернее отделение

        • Другое

      • Воскресная компьютерная школа

        • Пользователь компьютера плюс

        • Пользователь прикладных программ

        • Программирование I ступень

        • Программирование II ступень

        • Программирование III ступень

        • Архив

      • Воскресная математическая школа

        • Открытое тестирование РНОМЦ и мехмата ЮФУ

          • Открытое тестирование РНОМЦ и мехмата ЮФУ - 2026

          • Открытое тестирование РНОМЦ и мехмата ЮФУ - 2025

        • Олимпиадная математическая школа

        • Повышение квалификации

        • Доступная математика

        • Лаборатория математического онлайн-образования мех...

        • Осенняя универсиада

        • Научно-практическая конференция

        • ВМШ

          • ВМШ -2025

        • Летняя олимпиадная математическая школа РНОМЦ и ме...

      • Государственная итоговая аттестация

      • Дополнительное образование

      • Олимпиады

      • Видеолекции

      • Разное

      • Архив курсов

      • Заочная школа мехмата ЮФУ

You are currently using guest access (Log in)
Python Eng
Data retention summary
Get the mobile app Яндекс.Метрика