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

Worksheet Variables in Python

Uploaded by

Manas and Mohit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Worksheet Variables in Python

Uploaded by

Manas and Mohit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Worksheet: Variables in Python

Examples

1. Example 1: Storing Your Favorite Color


favorite_color = "Blue"
print(favorite_color)
This code stores the word "Blue" in the variable called favorite_color.

2. Example 2: Storing Your Age


my_age = 9
print(my_age)
The number 9 is stored in the variable my_age.

3. Example 3: Adding Two Numbers


number1 = 7
number2 = 3
total = number1 + number2
print(total)
This code adds two numbers and stores the result in the variable total.

4. Example 4: Subtracting Two Numbers


bigger_number = 10
smaller_number = 4
difference = bigger_number - smaller_number
print(difference)
This code subtracts two numbers and stores the result in difference.

5. Example 5: Using Variables to Store a Name


student_name = "Lavania"
print(student_name)
This code stores the student’s name in the variable student_name.

Questions

1. Question 1:
Create a variable called my_name and store your name in it. Print the variable.
# Write your code here

2. Question 2:
Create a variable called my_favorite_food and store your favorite food in it. Print the
variable.
# Write your code here

3. Question 3:
Create two variables called x and y. Store the numbers 4 and 6 in them. Add them
together and store the answer in a variable called sum. Print sum.
# Write your code here
4. Question 4:
Create two variables called apples and bananas. Store the numbers 5 and 8 in them.
Subtract the number of apples from the number of bananas and store the result in a
variable called fruit_difference. Print fruit_difference.
# Write your code here

5. Question 5:
Look at this variable name: my_home_city.
Is this a correct name for a variable? Why or why not?

You might also like