0% found this document useful (0 votes)
3 views

pROBLEMS

The document provides a series of programming exercises focused on variables, data types, input/output, operators, and control flow in Python. It includes tasks such as creating variables, performing arithmetic operations, and implementing simple calculators and guessing games. Each section outlines specific programming challenges along with example solutions.

Uploaded by

khaydarov.anvar
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)
3 views

pROBLEMS

The document provides a series of programming exercises focused on variables, data types, input/output, operators, and control flow in Python. It includes tasks such as creating variables, performing arithmetic operations, and implementing simple calculators and guessing games. Each section outlines specific programming challenges along with example solutions.

Uploaded by

khaydarov.anvar
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
You are on page 1/ 5

1.

Variables and Data Types

1. Assigning Variables
Create a variable name and store your name in it. Create another variable age and store your age. Print
both using:

print("Name:", name)
print("Age:", age)

2. Data Types
Identify the data type of each variable:

my_name = "Alice"
my_age = 13
my_height = 4.9
is_student = True

Write the data type for each variable in a comment.

2. Input and Output

1. Simple Input and Output


Write a program that:
o Asks the user for their favorite color.
o Prints a message like: "Your favorite color is [color]."
2. Addition with Input
Write a program that:
o Asks the user to enter two numbers.
o Adds the numbers and prints the result.

Example:

Enter first number: 10


Enter second number: 20
The sum is: 30

3. Operators

1. Arithmetic Operations
Write a program to calculate the area of a rectangle:
o Take the length and width as inputs.
o Print the area using length * width.
2. Comparison Operators
Write a program that:
o Takes two numbers as input.
o Checks if the first number is greater than the second and prints True or False.

Example:

Enter first number: 7


Enter second number: 5
Is the first number greater than the second? True

4. Control Flow

1. Even or Odd
Write a program that:
o Asks the user for a number.
o Checks if the number is even or odd using the modulus operator (%).
o Prints "Even" or "Odd".
2. Grading System
Write a program that:
o Takes a percentage score as input.
o Prints the grade based on the score:
 90-100: A
 75-89: B
 50-74: C
 Below 50: F
3. Simple Calculator
Write a program that:
o Asks the user to enter two numbers and an operator (+, -, *, /).
o Performs the operation and prints the result.

Example:

Enter first number: 8


Enter second number: 2
Enter operator (+, -, *, /): /
Result: 4.0

5. Combined Practice

1. Guess the Number


Write a program that:
o Sets a secret number (e.g., secret = 7).
o Asks the user to guess the number.
o If the guess is correct, print "You guessed it!"
o If the guess is too high, print "Too high!"
o If the guess is too low, print "Too low!"
2. Discount Calculator
Write a program that:
o Takes the price of an item and a discount percentage as input.
o Calculates and prints the final price after applying the discount.

Example:

Enter price: 100


Enter discount (%): 20
Final price: 80.0
solutions

1. Variables and Data Types

1. Assigning Variables

name = "Alice"
age = 13
print("Name:", name)
print("Age:", age)

2. Data Types

my_name = "Alice" # str (string)


my_age = 13 # int (integer)
my_height = 4.9 # float
is_student = True # bool (boolean)

2. Input and Output

1. Simple Input and Output

favorite_color = input("What is your favorite color? ")


print("Your favorite color is", favorite_color)

2. Addition with Input

num1 = int(input("Enter first number: "))


num2 = int(input("Enter second number: "))
result = num1 + num2
print("The sum is:", result)

3. Operators

1. Arithmetic Operations

length = float(input("Enter the length of the rectangle: "))


width = float(input("Enter the width of the rectangle: "))
area = length * width
print("The area of the rectangle is:", area)

2. Comparison Operators

num1 = int(input("Enter first number: "))


num2 = int(input("Enter second number: "))
print("Is the first number greater than the second?", num1 > num2)

4. Control Flow

1. Even or Odd

number = int(input("Enter a number: "))


if number % 2 == 0:
print("Even")
else:
print("Odd")

2. Grading System

score = int(input("Enter your percentage score: "))


if 90 <= score <= 100:
print("Grade: A")
elif 75 <= score < 90:
print("Grade: B")
elif 50 <= score < 75:
print("Grade: C")
else:
print("Grade: F")

3. Simple Calculator

num1 = float(input("Enter first number: "))


num2 = float(input("Enter second number: "))
operator = input("Enter operator (+, -, *, /): ")

if operator == "+":
result = num1 + num2
elif operator == "-":
result = num1 - num2
elif operator == "*":
result = num1 * num2
elif operator == "/":
if num2 != 0:
result = num1 / num2
else:
result = "Error! Division by zero."
else:
result = "Invalid operator."

print("Result:", result)

5. Combined Practice

1. Guess the Number

secret = 7
guess = int(input("Guess the secret number (1-10): "))

if guess == secret:
print("You guessed it!")
elif guess > secret:
print("Too high!")
else:
print("Too low!")

2. Discount Calculator

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


discount = float(input("Enter discount (%): "))
final_price = price - (price * discount / 100)
print("Final price:", final_price)

You might also like