i = 2 + 3
print(i)
i = i + 7
print("i = ", i)
n
be after the following Python instructions are executed?
j = 5
k = 10
n = j*k
n = n+1
int(3.2)
What happens? Try running the same command a few more times, each time replacing the 3.2
by some other number. What do you think int
does in Python?
float(7)
What happens? Try running the same command a few more times, each time replacing the 7
by some other number. What do you think float
does in Python?
Compute one third of 45.
Compute the number of seconds in a year.
num = num * 2
print(num)
Do this several times. Can you explain what is happening to the variable num
?
Given two variables up
and down
with the values 100
and -50
respectively, swap their values using a temporary variable.
kid1 = "red"
kid2 = "blue"
kid3 = "green"
Using only the three kid
variables and a temporary variable. Switch the values such that kid1’s favorite color is BLUE, kid2’s favorite color is GREEN, and kid3’s favorite color is RED.
variables.py
saved to the cs100/ch1
folder you created on the desktop.i = 2 + 3
print(i)
i = i + 7
print("i = ", i)
p
; then, print out the value of p
with a message similar to “p is 20” (just like you did with the variable i
).x
. Print the result as “The power is: ___” , where your answer fills in the blank.avg
; then, display it with a message similar to “The average of these numbers is 19.25”.pi
with the value 3.14159
. Use it to compute the area of a circle with radius 3, and print out the result.Submit your variables.py
file to Activity 3 on Moodle. Make sure it runs without errors!