Advertisement
horozov86

Error Handling Numbers Dictionary

Jun 2nd, 2023
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. numbers_dictionary = {}
  2.  
  3. line = input()
  4. while line != "Search":
  5.     number_as_string = line
  6.     try:
  7.         number = int(input())
  8.         numbers_dictionary[number_as_string] = number
  9.     except ValueError:
  10.         print("The variable number must be an integer")
  11.     line = input()
  12.    
  13. line = input()
  14. while line != "Remove":
  15.     searched = line
  16.     try:
  17.         print(numbers_dictionary[searched])
  18.     except KeyError:
  19.         print("Number does not exist in dictionary")
  20.     line = input()
  21.    
  22. line = input()
  23. while line != "End":
  24.     searched = line
  25.     try:
  26.         del numbers_dictionary[searched]
  27.     except KeyError:
  28.         print("Number does not exist in dictionary")
  29.     line = input()
  30.    
  31. print(numbers_dictionary)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement