Exercises - Python Variable Assignment
Variables Practice
What will be printed to the screen after running each of these snippets of code? Talk to a partner and write down your answers. Then, see if you were right by writing the examples in a file named variables_practice.py
and running the file from the command line.
What is the outcome of running the code below?
a = 25
b = 36
print a * b
What is the outcome of running the code below?
dog = "Ralph"
cat = "Whiskers"
print dog + cat
What is the outcome of running the code below?
band = "The Beatles"
print "My favorite band is " + band
Write the code to find the difference between the product and sum of three numbers
- Set
x
equal to 34679 - Set
y
equal to 566 - Set
z
equal to 47 - Output the product of
x
,y
, andz
- Assign the product to a variable
- Output the sum of
x
,y
, andz
- Assign the sum to a variable
- Output the difference between the product and the sum