muhammad_nasif

TASK_08

Apr 12th, 2021
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. str_val = input("Enter Dictionary: ")
  2.  
  3. #str_val = "{'Jon':100,'Dan':200,'Rob':300,'Nasif':120}"
  4.  
  5. str_val = str_val.replace("{", "")
  6. str_val = str_val.replace("}", "")
  7.  
  8. new_str = str_val.split(",")
  9.  
  10. summation = 0
  11. i = 0
  12.  
  13. for data in new_str:
  14.     section = data.split(":")
  15.     summation += int(section[1])
  16.     i += 1
  17.  
  18. # print(int(summation/i))         #WITH INTEGER TYPECASTING
  19. print(summation / i)  # WITHOUT INTEGER TYPECASTING
  20.  
Advertisement
Add Comment
Please, Sign In to add comment