Python
The following program contains a number of minor typos. Write
the correct code and
comments about what was wrong. The type function returns the type
for the value specified
as a parameter.
lex = {}
lex{’a’} = ’hej’
lex[’b’] = [5 9]
for k in lex.keys:
print(’Information for key {k}’)
print f’Val: {lex[k]}, Type: {type(lex[k])}’
lex = {}
#incorrect syntax
lex['a'] = 'hej'
#comma should be present in between 5 and 9 because they're list
lex['b'] = [5, 9]
#use keys() builtin method
for k in lex.keys():
#indentation should be followed
print('Information for key {k}')
#syntax error: print should be print() parentheses missed
print (f'Val: {lex[k]}, Type: {type(lex[k])}')
Get Answers For Free
Most questions answered within 1 hours.