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

Programming Fundamentals (Python)

  1. Home
  2. Courses
  3. Осенний семестр
  4. Python Eng
  5. Module 1: Basics and Conditions
  6. Module 1.3 - Built‑in Functions, Strings & mat...

Module 1.3 - Built‑in Functions, Strings & math Module

Due: Thursday, 29 October 2026, 7:32 PM
Completion requirements

Python Programming: Built‑in Functions, Strings, and the math Module

For English‑speaking students  |  max, min, abs, len, string ops, and math utilities

📑 Table of Contents

  • 🔹 Lab 2.1 – Max/Min (no built‑ins)
  • 🔹 Lab 2.2 – Max/Min (built‑ins)
  • 🔹 Lab 2.3 – Absolute Sum
  • 🔹 Lab 2.4 – String Concatenation
  • 🔹 Lab 2.5 – String Length & Border
  • 🔹 Lab 2.6 – Substring with in
  • 🔹 Lab 2.7 – Vowel Checker
  • 🔹 Lab 2.8 – Circle Area (math.pi)
  • 🔹 Lab 2.9 – Euclidean Distance
  • 🔹 Lab 2.10 – ceil / floor
  • 🔸 Practice Exercises
  • 🔸 Answer Key

Laboratory Works (2.1 – 2.10)

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

Lab 2.1 – Maximum and Minimum of Three Numbers (no built‑ins)

Score: 0.2

Task: Write a program that reads three numbers and prints their maximum and minimum without using max() and min() (to practice conditional statements).

📌 Algorithm

  1. Read three numbers from the user.
  2. Use if/elif/else to find the maximum by comparing each pair.
  3. Use a similar approach to find the minimum.
  4. Print both results.

💻 Solution Code


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))

# Find maximum
if a >= b and a >= c:
    maximum = a
elif b >= a and b >= c:
    maximum = b
else:
    maximum = c

# Find minimum
if a <= b and a <= c:
    minimum = a
elif b <= a and b <= c:
    minimum = b
else:
    minimum = c

print("Maximum:", maximum)
print("Minimum:", minimum)
        

📤 Expected Output

Enter first number: 5
Enter second number: 12
Enter third number: 8
Maximum: 12
Minimum: 5
📖 Step‑by‑Step Explanation
  1. Read three numbers from the user.
  2. Use if/elif/else to find the maximum by checking each possibility.
  3. Use the same approach to find the minimum.
  4. Print both results.

Lab 2.2 – Using Built‑in Functions max() and min()

Score: 0.2

Task: Write a program that reads three numbers and prints their maximum and minimum using max() and min().

📌 Algorithm

  1. Read three numbers.
  2. Use max(a, b, c) to find the maximum directly.
  3. Use min(a, b, c) to find the minimum directly.
  4. Print both results.

💻 Solution Code

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))

print("Maximum:", max(a, b, c))
print("Minimum:", min(a, b, c))

📤 Expected Output

Enter first number: 5
Enter second number: 12
Enter third number: 8
Maximum: 12
Minimum: 5
📖 Step‑by‑Step Explanation
  1. Read three numbers.
  2. max() returns the largest value among the arguments.
  3. min() returns the smallest value.
  4. Print the results.

Lab 2.3 – Absolute Value Sum

Score: 0.2

Task: Write a program that reads 5 numbers and prints the sum of their absolute values.

📌 Algorithm

  1. Read numbers.
  2. Compute the sum of absolute values.
  3. Print the result.

💻 Solution Code

a = float(input("Enter number 1: "))
b = float(input("Enter number 2: "))
c = float(input("Enter number 3: "))
d = float(input("Enter number 4: "))
e = float(input("Enter number 5: "))

result = abs(a) + abs(b) + abs(c) + abs(d) + abs(e)
print(result)

📤 Expected Output

Enter number 1: -5
Enter number 2: 3
Enter number 3: -2
Enter number 4: 7
Enter number 5: -1
Sum of absolute values: 18

Lab 2.4 – String Concatenation

Score: 0.2

Task: Write a program that reads a first name and a last name, then prints a greeting.

📌 Algorithm

  1. Read first name and last name.
  2. Use concatenation to build the greeting string.
  3. Print the result.

💻 Solution Code

first = input("Enter first name: ")
last = input("Enter last name: ")

greeting = "Hello " + first + " " + last + "! Welcome to Python!"
print(greeting)

📤 Expected Output

Enter first name: John
Enter last name: Smith
Hello John Smith! Welcome to Python!
📖 Step‑by‑Step Explanation
  1. Read first name and last name.
  2. Concatenate strings using + to form the greeting.
  3. Print the complete greeting.

Lab 2.5 – String Length and Repetition

Score: 0.2

Task: Write a program that reads a string and prints a border of * characters around it.

📌 Algorithm

  1. Read the word.
  2. Calculate its length using len().
  3. Print a top border of stars: '*' * (length + 8).
  4. Print the word with stars on both sides: '* ' + word + ' *'.
  5. Print a bottom border of stars (same as top).

💻 Solution Code

word = input("Enter a word: ")
length = len(word)

print('*' * (length + 8))
print('*   ' + word + '     *')
print('*' * (length + 8))

📤 Expected Output

Enter a word: Python
****************
*   Python     *
****************
📖 Step‑by‑Step Explanation
  1. Read the word and compute its length.
  2. Print a top border of stars using repetition.
  3. Print the word padded with spaces and stars.
  4. Print a bottom border identical to the top.

Lab 2.6 – Checking Substring with in

Score: 0.2

Task: Write a program that checks if a string contains the letter 'e'.

📌 Algorithm

  1. Read the input string.
  2. Use in to check if 'e' is in the string.
  3. Print the appropriate message.

💻 Solution Code

s = input("Enter a string: ")

if 'e' in s:
    print("The string contains the letter 'e'")
else:
    print("The string does not contain the letter 'e'")

📤 Expected Output

Enter a string: Hello
The string contains the letter 'e'
📖 Step‑by‑Step Explanation
  1. Read the input string.
  2. Use in to test membership of 'e'.
  3. Print a message based on the result.

Lab 2.7 – Vowel Checker

Score: 0.2

Task: Write a program that checks if a character is a vowel using in.

📌 Algorithm

  1. Read the character.
  2. Check that it's a single character.
  3. Use in to check if it's in the set of vowels ('aeiouAEIOU').
  4. Print the result.

💻 Solution Code

char = input("Enter a character: ")

if len(char) == 1 and char in 'aeiouAEIOU':
    print("Vowel")
else:
    print("Not a vowel")

📤 Expected Output

Enter a character: a
Vowel
📖 Step‑by‑Step Explanation
  1. Read the character.
  2. Ensure it's a single character with len().
  3. Use in to test against the string of vowels.
  4. Print the result.

Lab 2.8 – Using the math Module – Circle Area

Score: 0.2

Task: Write a program that reads the radius of a circle and calculates its area and circumference.

Formulas: Area = π × r², Circumference = 2 × π × r

📌 Algorithm

  1. Import the math module.
  2. Read the radius.
  3. Calculate the area using math.pi.
  4. Calculate the circumference using math.pi.
  5. Print both results.

💻 Solution Code

import math

radius = float(input("Enter radius: "))

area = math.pi * radius ** 2
circumference = 2 * math.pi * radius

print("Area:", area)
print("Circumference:", circumference)

📤 Expected Output

Enter radius: 5
Area: 78.53981633974483
Circumference: 31.41592653589793
📖 Step‑by‑Step Explanation
  1. Import the math module to access pi.
  2. Read the radius as a float.
  3. Compute area and circumference using math.pi.
  4. Print the results.

Lab 2.9 – Using math.sqrt() – Euclidean Distance

Score: 0.2

Task: Write a program that reads two points (x1, y1) and (x2, y2) and calculates the distance between them.

Formula: distance = sqrt((x2-x1)² + (y2-y1)²)

📌 Algorithm

  1. Import math.
  2. Read the coordinates of both points.
  3. Calculate the differences in x and y.
  4. Use math.sqrt() to calculate the distance.
  5. Print the result.

💻 Solution Code

import math

x1 = float(input("Enter x1: "))
y1 = float(input("Enter y1: "))
x2 = float(input("Enter x2: "))
y2 = float(input("Enter y2: "))

dx = x2 - x1
dy = y2 - y1
distance = math.sqrt(dx ** 2 + dy ** 2)

print("Distance:", distance)

📤 Expected Output

Enter x1: 0
Enter y1: 0
Enter x2: 3
Enter y2: 4
Distance: 5.0
📖 Step‑by‑Step Explanation
  1. Import math.
  2. Read all four coordinates.
  3. Compute the differences in x and y.
  4. Apply the Euclidean distance formula using math.sqrt().
  5. Print the distance.

Lab 2.10 – Using math.ceil() and math.floor()

Score: 0.2

Task: Write a program that reads a number and prints its ceiling and floor.

📌 Algorithm

  1. Import math.
  2. Read the number.
  3. Use math.ceil() to round up.
  4. Use math.floor() to round down.
  5. Print both results.

💻 Solution Code

import math

num = float(input("Enter a number: "))

print("Ceiling:", math.ceil(num))
print("Floor:", math.floor(num))

📤 Expected Output

Enter a number: 3.7
Ceiling: 4
Floor: 3
📖 Step‑by‑Step Explanation
  1. Import math.
  2. Read a floating‑point number.
  3. math.ceil() returns the smallest integer ≥ the number.
  4. math.floor() returns the largest integer ≤ the number.
  5. Print both.

✏️ Practice Exercises (Independent Work)

Try these on your own. Each practice includes a hint. Score: 0.5 each.

Practice 1 – Maximum of Four Numbers

Score: 0.5

Task: Write a program that reads 4 numbers and prints the maximum using max().

Enter number 1: 7
Enter number 2: 3
Enter number 3: 9
Enter number 4: 5
Maximum: 9
📖 Algorithm
  1. Read four numbers.
  2. Pass all four to max().
  3. Print the result.

Practice 2 – Absolute Difference

Score: 0.5

Task: Write a program that reads two numbers and prints their absolute difference.

Enter first number: 5
Enter second number: 12
Absolute difference: 7
📖 Algorithm
  1. Read two numbers.
  2. Compute abs(a - b).
  3. Print the result.

Practice 3 – String Length

Score: 0.5

Task: Write a program that reads a string and prints its length, and also repeats the string length times..

Enter a string: Hello World
Length: 11  Hello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello World
📖 Algorithm
  1. Read a string.
  2. Use len() to get its length.
  3. Print the length.

Practice 4 – Greeting Generator

Score: 0.5

Task: Read a title, first name, and last name, then print a formal greeting.

Enter title: Mr
Enter first name: John
Enter last name: Smith
Mr John Smith, welcome to the course!
📖 Algorithm
  1. Read title, first name, last name.
  2. Concatenate with commas and welcome message.
  3. Print the greeting.

Practice 5 – Password Strength Checker

Score: 0.5

Task: Check if a password contains !, @, or # using in.

Enter password: hello!123
Strong password
📖 Algorithm
  1. Read the password.
  2. Check if any of the special characters are present using or with in.
  3. Print "Strong password" if any is present, else "Weak password".

Practice 6 – Contains Space

Score: 0.5

Task: Check if a string contains a space.

Enter a string: Hello World
Contains a space
📖 Algorithm
  1. Read the string.
  2. Use ' ' in s to test for space.
  3. Print the appropriate message.

Practice 7 – Sector Calculations

Score: 0.5

Task: Read radius and central angle (in degrees), calculate area and arc length of a circular sector using math.pi and math.radians.

Formulas:
Area: 1/2 r2 0 (where θ in radians)
Arc length: L=rθ (where θ in radians)

Enter radius: 10
Enter angle (degrees): 45
Area: 39.269908169872416
Arc length: 7.853981633974483
📖 Algorithm
  1. Import math.
  2. Read radius (float) and angle_deg (float).
  3. Convert angle to radians: math.radians.
  4. Compute area = 0.5 * radius**2 * angle_rad
  5. Compute arc_length = radius * angle_rad.
  6. Print both.

Practice 8 – Pythagorean Theorem

Score: 0.5

Task: Read the two shorter sides and calculate the hypotenuse using math.sqrt().

Enter side a: 3
Enter side b: 4
Hypotenuse: 5.0
📖 Algorithm
  1. Import math.
  2. Read sides a and b.
  3. Compute hypotenuse = math.sqrt(a**2 + b**2).
  4. Print the result.

Practice 9 – Quadratic Equation (Discriminant)

Score: 0.5

Task: Calculate the discriminant D = b² - 4ac.

Enter a: 1
Enter b: -5
Enter c: 6
Discriminant: 1
📖 Algorithm
  1. Read a, b, c.
  2. Compute discriminant = b**2 - 4*a*c.
  3. Print the discriminant.

Practice 10 – Factorial

Score: 0.5

Task: Read n and calculate n! using math.factorial().

Enter n: 5
5! = 120
📖 Algorithm
  1. Import math.
  2. Read n as integer.
  3. Compute math.factorial(n).
  4. Print the result.

Practice 11 – Soccer Team Name

Score: 0.5

Task: Read a team name and print its length.

Enter team name: Barcelona
Barcelona has 9 characters
📖 Algorithm
  1. Read team name.
  2. Print the name and its length using len().

Practice 12 – City Names (shortest/longest)

Score: 0.5

Task: Read 3 city names and find the shortest and longest using min() and max() with key=len.

Enter city 1: Paris
Enter city 2: London
Enter city 3: Tokyo
Shortest: Paris
Longest: London
📖 Algorithm
  1. Read three city names.
  2. Use min(cities, key=len) for shortest.
  3. Use max(cities, key=len) for longest.
  4. Print both.

Practice 13 – Temperature Converter (round)

Score: 0.5

Task: Convert Celsius to Fahrenheit and round to 2 decimals using round().

Enter temperature in Celsius: 36.6
36.6°C = 97.88°F
📖 Algorithm
  1. Read Celsius.
  2. Compute Fahrenheit = C * 9/5 + 32.
  3. Use round(F, 2) to format.
  4. Print both.

Practice 14 – Email Validator (Part 1)

Score: 0.5

Task: Check if a string contains both @ and ..

Enter email: user@example.com
Valid
📖 Algorithm
  1. Read email.
  2. Check '@' in email and '.' in email.
  3. Print "Valid" or "Invalid".

Practice 15 – Word Pattern

Score: 0.5

Task: Read a word and create a pattern with asterisks around it.

Enter a word: Hello
*******
*Hello*
*******
📖 Algorithm
  1. Read the word.
  2. Compute length.
  3. Print top border: '*' * (length+6).
  4. Print middle: '*' + ' ' + word + ' ' + '*'.
  5. Print bottom border same as top.

🔑 Answer Key – Practice Exercises

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

Practice 1 – Solution

a = int(input("Enter number 1: "))
b = int(input("Enter number 2: "))
c = int(input("Enter number 3: "))
d = int(input("Enter number 4: "))
print("Maximum:", max(a, b, c, d))

Practice 2 – Solution

a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
print("Absolute difference:", abs(a - b))

Practice 3 – Solution

s = input("Enter a string: ")
print("Length:", len(s))

Practice 4 – Solution

title = input("Enter title: ")
first = input("Enter first name: ")
last = input("Enter last name: ")
greeting = title + " " + first + " " + last + ", welcome to the course!"
print(greeting)

Practice 5 – Solution

password = input("Enter password: ")
if '!' in password or '@' in password or '#' in password:
    print("Strong password")
else:
    print("Weak password")

Practice 6 – Solution

s = input("Enter a string: ")
if ' ' in s:
    print("Contains a space")
else:
    print("Does not contain a space")

Practice 7 – Solution

import math
radius = float(input("Enter radius: "))
area = math.pi * radius ** 2
circumference = 2 * math.pi * radius
print("Area:", area)
print("Circumference:", circumference)

Practice 8 – Solution

import math
a = float(input("Enter side a: "))
b = float(input("Enter side b: "))
c = math.sqrt(a ** 2 + b ** 2)
print("Hypotenuse:", c)

Practice 9 – Solution

a = float(input("Enter a: "))
b = float(input("Enter b: "))
c = float(input("Enter c: "))
discriminant = b ** 2 - 4 * a * c
print("Discriminant:", discriminant)

Practice 10 – Solution

import math
n = int(input("Enter n: "))
print(n, "! =", math.factorial(n))

Practice 11 – Solution

team = input("Enter team name: ")
print(team, "has", len(team), "characters")

Practice 12 – Solution

city1 = input("Enter city 1: ")
city2 = input("Enter city 2: ")
city3 = input("Enter city 3: ")
print("Shortest:", min(city1, city2, city3, key=len))
print("Longest:", max(city1, city2, city3, key=len))

Practice 13 – Solution

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

Practice 14 – Solution

email = input("Enter email: ")
if '@' in email and '.' in email:
    print("Valid")
else:
    print("Invalid")

Practice 15 – Solution

word = input("Enter a word: ")
length = len(word)
print('*' * (length + 6))
print('*' + ' ' * 2 + word + ' ' * 2 + '*')
print('*' * (length + 6))

📋 Quick Reference – Built‑ins, Strings & math

Built‑in Functions

  • min(a,b,c) → smallest
  • max(a,b,c) → largest
  • abs(x) → absolute value
  • len(s) → string length
  • str(x) → convert to string

String Operations

"Hello" + " " + "World"  # concatenation
"Hi" * 3                 # repetition
len("Python")          # → 6
'e' in "Hello"         # → True

math Module

import math
math.sqrt(16)   # → 4.0
math.ceil(3.7) # → 4
math.floor(3.7) # → 3
math.factorial(5) # → 120
math.pi          # ≈ 3.14159

© 2026 Python Module – Built‑ins, Strings & math  |  Keep coding!

◄ Module 1.2 – Conditional Statements
Module 2.1 – The for Loop ►

Blocks

Skip Navigation

Navigation

  • Home

    • Site pages

      • My courses

      • Tags

    • My courses

    • Courses

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

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

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

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

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

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

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

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

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

        • Другое

        • Этика ИИ

        • ОНС-Н_1

        • Прогр-ММ-2

        • Прогр-ММ-1

        • АБиМ-ИИБ26

        • МСиТВ_АБМ_2026

        • Python Eng

          • General

          • Module 1: Basics and Conditions

            • AssignmentModule 1.1 – Fundamentals

            • AssignmentModule 1.2 – Conditional Statements

            • AssignmentModule 1.3 - Built‑in Functions, Strings & mat...

          • Module 2: LOOPs

          • Module 3: Strings and Slices

          • Topic 3

          • Topic 4

          • Topic 5

          • Topic 6

          • Topic 7

          • Topic 8

          • Topic 9

          • Topic 10

        • Экзамен ИКТ

        • ТестИИ

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

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

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

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

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

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

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

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

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

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

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

        • Другое

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

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

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

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

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

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

        • Архив

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

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

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

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

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

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

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

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

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

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

        • ВМШ

          • ВМШ -2025

          • ВМШ - 2026

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

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

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

      • Олимпиады

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

      • Разное

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

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

Supplementary blocks

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