import random tosses = [] def toss(aNumber): for x in range(aNumber): tosses.append(random.choice(['heads', 'tails'])) def returnResult(): tosses.clear() if times == 1: toss(times) print(f'It\'s {tosses[-1]}!') elif times > 1: if times == 69: print("\nNice") toss(times) headsAmount = tosses.count("heads") headsPercent = headsAmount / times * 100 tailsAmount = tosses.count("tails") tailsPercent = tailsAmount / times * 100 print( f'\nOut of {times} tosses, {headsAmount} were heads and {tailsAmount} were tails.') print( f'So you\'ve got {headsPercent:.2f}% heads and {tailsPercent:.2f}% tails.\n') while True: userInput = input("\nHow many times do you wanna toss a coin? : ") if userInput.isdigit() and int(userInput) > 0: times = int(userInput) returnResult() if (input("\nWanna play again?(Y/n): ").lower() == 'y'): continue else: print("\n?? :(\n") break else: print('\nOnly positive integers please... \nNow...')