pROBLEMS
pROBLEMS
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
Example:
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:
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:
5. Combined Practice
Example:
1. Assigning Variables
name = "Alice"
age = 13
print("Name:", name)
print("Age:", age)
2. Data Types
3. Operators
1. Arithmetic Operations
2. Comparison Operators
4. Control Flow
1. Even or Odd
2. Grading System
3. Simple Calculator
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
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