Computer Science
Related Questions
Predict the output:
arr = {} arr[1] = 1 arr['1'] = 2 arr[1] += 1 sum = 0 for k in arr: sum += arr[k] print(sum)Predict the output
a = {(1,2):1,(2,3):2} print(a[1,2])Find the error/output. Consider below given two sets of codes. Which one will produce an error? Also, predict the output produced by the correct code.
(a)
box = {} jars = {'Jam' :4} crates = {} box['biscuit'] = 1 box['cake'] = 3 crates['box'] = box crates['jars'] = jars print(len(crates[box]))(b)
box = {} jars = {'Jam' :4} crates = {} box['biscuit'] = 1 box['cake'] = 3 crates['box'] = box crates['jars'] = jars print(len(crates['box']))Predict the output :
dct = {} dct[1] = 1 dct ['1'] = 2 dct[1.0] = 4 sum = 0 for k in dct: print(k, sum) sum += dct[k] print(sum)