72.6k views
3 votes
Create a variable total of type Double set to 0. Then loop through the dictionary, and add the value of each integer and double to your variable's value. For each string value, add 1 to the total. For each boolean, add 2 to the total if the boolean is true, or subtract 3 if it's false. Print the value of total.

User Karancan
by
5.4k points

1 Answer

3 votes

Answer:

total = 0.0

for x in dictionary.values():

if x == str(x):

total += 1

elif x is bool:

total += 2 if x is True else total -3

else:

total += x

print( total )

Step-by-step explanation:

The python source code defines a variable 'total' and iterates through a dictionary and adds its values to the total variable. Finally, the total value is printed.

User Barnash
by
5.3k points