daily pastebin goal
78%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top