Advertisement
IT45200

Untitled

May 29th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.65 KB | None | 0 0
  1. import random
  2.  
  3.  
  4. def start():
  5.     print ("The computer will give you an amount.")
  6.     while game():
  7.         pass
  8.    
  9.    
  10. def game():
  11.    
  12.     print ("Enter coin values(one by one) that add up to the ammount.")
  13.     print ("You can use coin values of 1, 2, 5 and 10. when finished press ENTER\n")
  14.    
  15.     coin_value = ['', '1', '2', '5', '10']
  16.     total = 0
  17.     amount = random.randint(1,99)         #generates a random amount
  18.     print ("AMOUNT : ", amount, "\n")
  19.     c1 = input("Enter first coin : ")
  20.  
  21.     while c1 not in coin_value:
  22.         c1 = input("Pls enter coins of value 1, 2, 5 ,10 or press ENTER : ")
  23.  
  24.     if c1 != '' :
  25.         c1_value = int(c1)       #converting str to int
  26.         total = total + c1_value
  27.  
  28.         c_nxt = 0
  29.         while c_nxt != '' :
  30.             c_nxt = input("Enter next coin : ")
  31.  
  32.             while c_nxt not in coin_value:
  33.                 c_nxt = input("Pls enter coins of value 1, 2, 5, 10 or press ENTER : ")
  34.  
  35.             if c_nxt != '':    
  36.                 c_nxt_value = int(c_nxt)       #converting str to int
  37.                 total = total + c_nxt_value
  38.             else:
  39.                 print ("\nTotal value you entered is", total, "\n")
  40.  
  41.                 if total == amount :
  42.                     print ("You WON!!!")
  43.                    
  44.                 elif total > amount :
  45.                     exc = total - amount
  46.                     print ("Your entered value EXCEEDS the required value by", exc)
  47.                     print ("\nYou LOST!!!")
  48.                    
  49.                 elif total < amount:
  50.                     lss = amount - total
  51.                     print ("Your entered value is LESS THAN the required value by", lss)
  52.                     print ("\nYou LOST!!!")
  53.                    
  54.    
  55.     return retry()
  56.  
  57.  
  58. def retry():
  59.     r = input("Retry? (y/n) : ")
  60.                    
  61.     while r not in ['y', 'Y','n','N']:
  62.         r = input("Pls enter Y/N : ")
  63.  
  64.     if r == 'N' or r == 'n':
  65.         pass
  66.        
  67.     else:
  68.         game()
  69.            
  70. if __name__ == '__main__':
  71.     start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement