Advertisement
beccafuchs

LF6-TW2.5-AE-LS-1.4 OOP Flying Toaster

Jun 7th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.71 KB | None | 0 0
  1. #snippet to demonstrate how the Toaster and SuperToaster classes could be used in a small command line program
  2.  
  3. from flying_toaster.toaster import Toaster
  4. from flying_toaster.super_toaster import SuperToaster
  5.  
  6. def print_toaster(toaster):
  7.     print('model: ', type(toaster).__name__)
  8.     if isinstance(toaster, SuperToaster):    
  9.         print('alias: ', toaster.alias)
  10.     print('colour: ', toaster.colour)
  11.     print('number of slots: ', len(toaster.slots))
  12.  
  13. def get_toaster(toaster_type):
  14.     try:
  15.         slots = input('\nHow many slots?: ')
  16.         colour= input('\nWhich colour?: ')
  17.        
  18.         toaster = None
  19.  
  20.         if toaster_type == str(1):
  21.             toaster = Toaster(int(slots), colour)
  22.  
  23.         elif toaster_type == str(2):
  24.             alias = input('\nWhat is the alias of your toaster?: ')
  25.            
  26.             toaster = SuperToaster(int(slots), alias, colour)
  27.  
  28.         print('\nHere is your wonderful toaster!\n')
  29.         print_toaster(toaster)
  30.  
  31.         toasts = input('\nHow many toasts would you like?: ')
  32.         bread = input('\nWhich bread?: ')
  33.         toaster.add_toasts(int(toasts), bread)
  34.  
  35.         time = input('\nHow many seconds?: ')
  36.         toaster.set_timer(int(time))
  37.  
  38.         toaster.toast()
  39.    
  40.     except:
  41.         exit(1)
  42.  
  43. def main():
  44.     print('What toaster do you want?\n')
  45.     print('Toaster: press [1]')
  46.     print('SuperToaster: press [2]')
  47.  
  48.     toaster = input('\nToaster: ')
  49.    
  50.     if toaster in [str(1), str(2)]:
  51.         get_toaster(toaster)
  52.  
  53.     else:
  54.         print('\nInvalid input!')
  55.  
  56.     end_loop = input('\nExit program? [y/n]: ')
  57.  
  58.     if end_loop == 'n' or end_loop == 'N':
  59.         main()
  60.  
  61.  
  62. if __name__ == '__main__':
  63.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement