8. Multiple assignment¶
xxxxxxxxxx
n1, n2, n3, n4 = eval(input("Enter 4 grades separated by commas: "))
print("Mean:", (n1 + n2 + n3 + n4) / 4)
x = 4
y = 5
suma, difference = x + y, x - y
print(suma)
print(difference)
x, y = y, x
print(x, y)
Activity: 8.1 ActiveCode (ac_l40_8_en)
To swap variables, the following sequence does not work!
|
Activity: CodeLens 8.2 (cl_l40_8a_en)
One solution would be to use a
temp
variable.
|
Activity: CodeLens 8.3 (cl_l40_8b_en)
Multiple assignment can also be used, which is more elegant.
|
Activity: CodeLens 8.4 (cl_l40_8c_en)
You have attempted 1 of 3 activities on this page