Worksheet_2_-_Python__3_
Worksheet_2_-_Python__3_
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)
Ask the user for their name and print a greeting message, e.g., "Hello, [name]! Welcome to Python
programming!"
Ask the user to enter two numbers. Multiply the numbers and print the result.
5. Square a Number
Ask the user to enter a number. Calculate the square of that number and display it.
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]."
7. Convert Temperature
Ask the user to enter a temperature in Celsius. Convert the temperature to Fahrenheit using the formula:
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.
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)
Ask the user to input a number. Write a program to check if the number is even or odd and display the
result.
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.