Advertisement
Guest User

Untitled

a guest
Apr 16th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. # define Python user-defined exceptions
  2. class MyError(Exception):
  3. """Base class for other exceptions"""
  4. pass
  5.  
  6.  
  7. class KeyNoExist(MyError):
  8. """Raised when the input value is too small"""
  9. pass
  10.  
  11.  
  12. class ValueNoExist(MyError):
  13. pass
  14.  
  15.  
  16. def diction(slownik):
  17. for key in slownik:
  18. if (slownik[key] == podaj):
  19. print(key)
  20. return True
  21. elif (key == podaj):
  22. print(slownik[podaj])
  23. return True
  24.  
  25. return False
  26.  
  27.  
  28. def rekurencja(slownik):
  29. start = 0
  30. while start < 3:
  31. if diction(slownik):
  32. return True
  33. else:
  34. diction(slownik)
  35. start += 1
  36. return False
  37.  
  38. if not rekurencja(d):
  39. raise KeyNoExist
  40.  
  41.  
  42. d = dict(weather="clima", earth="terra", rain="chuva")
  43. podaj = input("Podaj słowo: ").lower()
  44.  
  45. if diction(d):
  46. print("Congratulations! You guessed it correctly.")
  47. else:
  48. print("That english word doesn't exist in our dictionary!")
  49. raise KeyNoExist
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement