Difference between revisions of "User:Praveer-mathur-9f3d@uni-bonn.de"
Jump to navigation
Jump to search
What datatype does the variable planet have?
What datatype does the variable apples have?
What datatype does the variable distance have?
What datatype does the variable false have?
| Line 189: | Line 189: | ||
+ Click and submit to see the answer | + Click and submit to see the answer | ||
|| <code>UniUniUni</code> | || <code>UniUniUni</code> | ||
| + | </quiz> | ||
| + | {{hidden end}} | ||
| + | |||
| + | === Short Quiz: Containers === <!--T:5--> | ||
| + | |||
| + | Read the following code: | ||
| + | |||
| + | <code>uni = {"departments": ["physics", "chemistry"], <br> "employees": 4000, <br> "campuses": ("Poppelsdorf", "Endenich"),}</code> | ||
| + | |||
| + | What do the following lines print? Keep in mind that the lines could also give an error output. | ||
| + | |||
| + | {{hidden begin | ||
| + | |title = <code>print(uni[0])</code> | ||
| + | }} | ||
| + | <quiz display=simple> | ||
| + | { | ||
| + | |type="()"} | ||
| + | + Click and submit to see the answer | ||
| + | || <code>KeyError: 0</code> | ||
| + | </quiz> | ||
| + | {{hidden end}} | ||
| + | |||
| + | {{hidden begin | ||
| + | |title = <code>print(uni["departments"][0]</code> | ||
| + | }} | ||
| + | <quiz display=simple> | ||
| + | { | ||
| + | |type="()"} | ||
| + | + Click and submit to see the answer | ||
| + | || <code>physics</code> | ||
| + | </quiz> | ||
| + | {{hidden end}} | ||
| + | |||
| + | {{hidden begin | ||
| + | |title = <code>print(uni["employees"] = 5000</code> | ||
| + | }} | ||
| + | <quiz display=simple> | ||
| + | { | ||
| + | |type="()"} | ||
| + | + Click and submit to see the answer | ||
| + | || Nothing | ||
| + | </quiz> | ||
| + | {{hidden end}} | ||
| + | |||
| + | {{hidden begin | ||
| + | |title = <code>print(uni["campuses"][0] = "Innenstadt</code> | ||
| + | }} | ||
| + | <quiz display=simple> | ||
| + | { | ||
| + | |type="()"} | ||
| + | + Click and submit to see the answer | ||
| + | || <code>TypeError: 'tuple' object does not support item assignment</code> | ||
| + | </quiz> | ||
| + | {{hidden end}} | ||
| + | |||
| + | {{hidden begin | ||
| + | |title = <code>print(uni["campuses"][0]</code> | ||
| + | }} | ||
| + | <quiz display=simple> | ||
| + | { | ||
| + | |type="()"} | ||
| + | + Click and submit to see the answer | ||
| + | || <code>Poppelsdorf</code> | ||
</quiz> | </quiz> | ||
{{hidden end}} | {{hidden end}} | ||
Revision as of 18:19, 9 March 2026
Short Quiz: Variable Assignment
What values do the two variables "mass" and "age" have in the following lines?
mass = 47.5
print(mass)
age = 122
print(mass, age)
mass = mass * 2.0
print(mass, age)
age = age - 20
print(mass, age)
Short Quiz: Data Types
planet = 'Earth' What datatype does the variable planet have?
apples = 5 What datatype does the variable apples have?
distance = 10.5 What datatype does the variable distance have?
false = 7 > 2 What datatype does the variable false have?
Short Quiz: Boolean Operations
var1 = True
What is the value of each variable after each of the following print statements?
var2 = False
print(var1, var2)
var2 = var1 or var2
print(var1, var2)
var1 = var1 and not var2
print(var1, var2)
var1 = not(var1 and not var1)
print(var1, var2)
Short Quiz: String Concatenation
str1 = "Uni"
str2 = "Bonn"
str3 = str2 + str1
str4 = str1 * 3
What output do you expect after doing
print(str3)?
What output do you expect after doing
print(str4)?
Short Quiz: Containers
Read the following code:
uni = {"departments": ["physics", "chemistry"],
"employees": 4000,
"campuses": ("Poppelsdorf", "Endenich"),}
What do the following lines print? Keep in mind that the lines could also give an error output.
print(uni[0])
print(uni["departments"][0]
print(uni["employees"] = 5000
print(uni["campuses"][0] = "Innenstadt
print(uni["campuses"][0]