import random def start(): print ("The computer will give you an amount.") while game(): pass def game(): print ("Enter coin values(one by one) that add up to the ammount.") print ("You can use coin values of 1, 2, 5 and 10. when finished press ENTER\n") coin_value = ['', '1', '2', '5', '10'] total = 0 amount = random.randint(1,99) #generates a random amount print ("AMOUNT : ", amount, "\n") c1 = input("Enter first coin : ") while c1 not in coin_value: c1 = input("Pls enter coins of value 1, 2, 5 ,10 or press ENTER : ") if c1 != '' : c1_value = int(c1) #converting str to int total = total + c1_value c_nxt = 0 while c_nxt != '' : c_nxt = input("Enter next coin : ") while c_nxt not in coin_value: c_nxt = input("Pls enter coins of value 1, 2, 5, 10 or press ENTER : ") if c_nxt != '': c_nxt_value = int(c_nxt) #converting str to int total = total + c_nxt_value else: print ("\nTotal value you entered is", total, "\n") if total == amount : print ("You WON!!!") elif total > amount : exc = total - amount print ("Your entered value EXCEEDS the required value by", exc) print ("\nYou LOST!!!") elif total < amount: lss = amount - total print ("Your entered value is LESS THAN the required value by", lss) print ("\nYou LOST!!!") return retry() def retry(): r = input("Retry? (y/n) : ") while r not in ['y', 'Y','n','N']: r = input("Pls enter Y/N : ") if r == 'N' or r == 'n': pass else: game() if __name__ == '__main__': start()