Python Datacamp Interm 3 100% Verified
error = 1
while error < 4:
print(error)
error = error + 1
what is the output? - ANSWER 1
2
3
fam = [1.73, 1.68, 1.71, 1.89]
print each of element seperately - ANSWER for height in fam :
print(height)
fam = [1.73, 1.68, 1.71, 1.89]
???
index 0: 1.73
index 1: 1.68
index 2: 1.71
index 3: 1.89 - ANSWER for index, height in enumerate(fam) :
print("index " + str(index) + ": " + str(height))
,house = [["hallway", 11.25],
["kitchen", 18.0],
["living room", 20.0],
["bedroom", 10.75],
["bathroom", 9.50]]
???
the hallway is 11.25 sqm
the kitchen is 18.0 sqm
the living room is 20.0 sqm
the bedroom is 10.75 sqm
the bathroom is 9.5 sqm - ANSWER for x in house:
print('the ' + x[0] + ' is ' + str(x[1]) +' sqm')
Loop over dictionary
world = { "afghanistan":30.55, "albania":2.77, "algeria":39.21 }
what order would the output take? - ANSWER items() method
for key, value in world.items() : print(key + " -- " + str(value))
algeria -- 39.21
afghanistan -- 30.55
albania -- 2.77
, the order in which they iterate is not fixed
dictionaries are inherently unordered
europe = {'spain':'madrid', 'france':'paris', 'germany':'berlin',
'norway':'oslo', 'italy':'rome', 'poland':'warsaw', 'austria':'vienna' }
???
the capital of norway is oslo
the capital of austria is vienna
the capital of spain is madrid
the capital of france is paris
the capital of italy is rome
the capital of poland is warsaw
the capital of germany is berlin - ANSWER for x, y in europe.items():
print ('the capital of ' + x + ' is ' + y)
loop for Numpy array
my_array([[ 74, 180],
[ 74, 215],
[ 72, 210], - ANSWER for 1D array
for x in my_array:
for 2D array:
function
error = 1
while error < 4:
print(error)
error = error + 1
what is the output? - ANSWER 1
2
3
fam = [1.73, 1.68, 1.71, 1.89]
print each of element seperately - ANSWER for height in fam :
print(height)
fam = [1.73, 1.68, 1.71, 1.89]
???
index 0: 1.73
index 1: 1.68
index 2: 1.71
index 3: 1.89 - ANSWER for index, height in enumerate(fam) :
print("index " + str(index) + ": " + str(height))
,house = [["hallway", 11.25],
["kitchen", 18.0],
["living room", 20.0],
["bedroom", 10.75],
["bathroom", 9.50]]
???
the hallway is 11.25 sqm
the kitchen is 18.0 sqm
the living room is 20.0 sqm
the bedroom is 10.75 sqm
the bathroom is 9.5 sqm - ANSWER for x in house:
print('the ' + x[0] + ' is ' + str(x[1]) +' sqm')
Loop over dictionary
world = { "afghanistan":30.55, "albania":2.77, "algeria":39.21 }
what order would the output take? - ANSWER items() method
for key, value in world.items() : print(key + " -- " + str(value))
algeria -- 39.21
afghanistan -- 30.55
albania -- 2.77
, the order in which they iterate is not fixed
dictionaries are inherently unordered
europe = {'spain':'madrid', 'france':'paris', 'germany':'berlin',
'norway':'oslo', 'italy':'rome', 'poland':'warsaw', 'austria':'vienna' }
???
the capital of norway is oslo
the capital of austria is vienna
the capital of spain is madrid
the capital of france is paris
the capital of italy is rome
the capital of poland is warsaw
the capital of germany is berlin - ANSWER for x, y in europe.items():
print ('the capital of ' + x + ' is ' + y)
loop for Numpy array
my_array([[ 74, 180],
[ 74, 215],
[ 72, 210], - ANSWER for 1D array
for x in my_array:
for 2D array:
function