User:Praveer-mathur-9f3d@uni-bonn.de/intro-to-programming-with-python
< User:Praveer-mathur-9f3d@uni-bonn.de
Jump to navigation
Jump to search
Revision as of 13:21, 17 March 2026 by Praveer-mathur-9f3d@uni-bonn.de (talk | contribs) (Created page with "=== Short Quiz: Variable Assignment === <!--T:5--> What values do the two variables "mass" and "age" have in the following lines? {{hidden begin |title = <code>mass = 47....")
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]
Short Quiz: Understanding if Statements
Which of the following statements would get printed?
if '':
print('empty string is true')
if 'word':
print('word is true')
if []:
print('empty list is true')
if [1, 2, 3]:
print('non-empty list is true')
if 0:
print('zero is true')
if 1:
print('one is true')
Short Quiz: Understanding for Loops
Consider the following Python code:
What does the output look like after the loop is done running?
numbers = [5, 8, -3, 6, 0, -2]
summed = 0
for num in numbers:
if num < 0:
continue
summed = summed + num
print(summed) What does the output look like after the loop is done running?
Short Quiz: Mutability
Will the following lines work or result in an error?
numbers = [5, 8, -3, 6, 0, -2]
numbers[3] = 1
string = "banana"
string[0] = "c"
languages = ("python", "C", "Fortran")
languages[1] = "C++"
alice = {"first_name": "Alice", "age": 32}
alice["age"] = 33
Short Quiz: Understanding Slicing
What will the following statements print?
string = "Uni Bonn"
print(string[5])
string = "Uni Bonn"
print(string[0:2])
string = "Uni Bonn"
print(string[5:])