Instructions
For each prompt, write a short Python code snippet to solve the problem described. Write your code in the
box provided.
1. Create a Variable
Declare a variable named my_age and assign your current age to it. Print the value of my_age.
my_age = 13
print(my_age)
2. Arithmetic Operations
Create two variables, x and y, with values 15 and 4. Perform and print the following operations:
● Addition
● Subtraction
● Multiplication
● Division
● Modulus
x = 15
y=4
print("Addition:", x + y)
print("Subtraction:", x - y)
print("Multiplication:", x * y)
print("Division:", x / y)
print("Modulus:", x % y)
3. User Input: Greeting
Ask the user for their name and print a greeting message, e.g., "Hello, [name]! Welcome to Python
programming!"
name = input("Enter your name: ")
print(f"Hello, {name}! Welcome to Python programming!")
4. Simple Calculation
Ask the user to enter two numbers. Multiply the numbers and print the result.
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
print("The product is:", num1 * num2)
5. Square a Number
Ask the user to enter a number. Calculate the square of that number and display it.
number = float(input("Enter a number: "))
print("The square is:", number ** 2)
6. Combining Strings
Ask the user to enter their first name and last name. Combine the two into a single string and display it in
the format: "Your full name is [first name] [last name]."
first_name = input("Enter your first name: ")
last_name = input("Enter your last name: ")
print(f"Your full name is {first_name} {last_name}.")
7. Convert Temperature
Ask the user to enter a temperature in Celsius. Convert the temperature to Fahrenheit using the formula:
Fahrenheit = (Celsius * 9/5) + 32
Print the converted temperature.
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9/5) + 32
print(f"The temperature in Fahrenheit is: {fahrenheit}")
8. Calculate Remainder
Create a program that asks the user to input two numbers. Calculate and display the remainder when the
first number is divided by the second number.
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
print(f"The remainder when {num1} is divided by {num2} is: {num1 % num2}")
9. Create and Swap Variables
Create two variables, a and b, and assign any values to them. Write code to swap their values and print the
results before and after swapping.
a=5
b = 10
print("Before swapping: a =", a, ", b =", b)
a, b = b, a
print("After swapping: a =", a, ", b =", b)
10. Check Even or Odd
Ask the user to input a number. Write a program to check if the number is even or odd and display the
result.
number = int(input("Enter a number: "))
if number % 2 == 0:
print(f"{number} is even.")
else:
print(f"{number} is odd.")
Bonus Challenge (Optional)
Write a Python script that asks the user to input their hourly wage and the number of hours they worked in a
week. Calculate and display their total earnings for the week.
hourly_wage = float(input("Enter your hourly wage: "))
hours_worked = float(input("Enter hours worked in a week: "))
total_earnings = hourly_wage * hours_worked
print(f"Your total earnings for the week are: {total_earnings}")