0% found this document useful (0 votes)
5 views3 pages

Python Basic Exercises

The document outlines ten basic programming problems and their solutions, covering topics such as arithmetic operations, temperature conversion, even/odd checks, age classification, and more. Each problem includes a brief description, relevant variables, and code snippets demonstrating the solution. The problems are designed to illustrate fundamental programming concepts and logical reasoning.

Uploaded by

Khinsandar Naing
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Python Basic Exercises

The document outlines ten basic programming problems and their solutions, covering topics such as arithmetic operations, temperature conversion, even/odd checks, age classification, and more. Each problem includes a brief description, relevant variables, and code snippets demonstrating the solution. The problems are designed to illustrate fundamental programming concepts and logical reasoning.

Uploaded by

Khinsandar Naing
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Basic Arithmetic

Problem: Calculate the area of a rectangle with length 8 and width 5.

# 1. Basic Arithmetic

length = 8

width = 5

area = length * width

print(f” Area of rectangle: {area}")

2. Temperature Conversion

Problem: Convert 100° Fahrenheit to Celsius using the formula: C = (F - 32) * 5/9

# 2. Temperature Conversion

fahrenheit = 100

celsius = (fahrenheit - 32) * 5/9

print(f”100°F = {celsius:.1f}°C")

3. Even or Odd Check

Problem: Check if a number (15) is even or odd.

# 3. Even or Odd Check

number = 15

is_even = number % 2 == 0

print(f"{number} is even: {is_even}")

4. Age Classifier

Problem: Check if a person (age 20) is a teenager (13-19 years old).

# 4. Age Classifier

age = 20

is_teenager = age >= 13 and age <= 19

print(f"Age {age} is teenager: {is_teenager}")


5. Simple Calculator

Problem: Perform all basic arithmetic operations on two numbers (12 and 4).

# 5. Simple Calculator

a, b = 12, 4

print(f" {a} + {b} = {a + b}")

print(f" {a} - {b} = {a - b}")

print(f" {a} * {b} = {a * b}")

print(f" {a} / {b} = {a / b}")

6. Logical AND/OR

Problem: Check if a number (25) is between 10 and 30 AND divisible by 5.

# 6. Logical AND

num = 25

condition = (num > 10) and (num < 30) and (num % 5 == 0)

print(f" {num} is between 10-30 and divisible by 5: {condition}")

7. Comparison Chain

Problem: Check if three numbers (5, 10, 15) are in ascending order.

# 7. Comparison Chain

x, y, z = 5, 10, 15

in_order = x < y < z

print(f"Numbers {x}, {y}, {z} are in ascending order: {in_order}")

8. Grade Calculator

Problem: Calculate average of three test scores (85, 90, 78) and check if it's a passing grade
(≥60).

# 8. Grade Calculator

score1, score2, score3 = 85, 90, 78

average = (score1 + score2 + score3) / 3


is_passing = average >= 60

print(f" Average: {average:.1f}, Passing: {is_passing}")

9. Number Properties

Problem: Check if a number (-7) is negative AND odd.

# 9. Number Properties

num2 = -7

is_negative_odd = num2 < 0 and num2 % 2 != 0

print(f" {num2} is negative and odd: {is_negative_odd}")

10. Voting Eligibility

Problem: Check if a person (age 17, citizen=True) is eligible to vote (age ≥ 18 and citizen).

# 10. Voting Eligibility

age = 17

is_citizen = True

can_vote = age >= 18 and is_citizen

print(f"Can vote: {can_vote}")

You might also like