Skip to main content
Became Hot Network Question
edited tags; edited title
Link
Reinderien
  • 65.5k
  • 5
  • 70
  • 188

Hello! Can someone rate my code? Coin-flipping game

Source Link

Hello! Can someone rate my code?

I'm 13 years old and turning 14 years soon! I Coded this simple text game in around 30 minutes, can someone rate it? and give some feedback

import random
import time
current_coin = 500
def play():
    computer2 = random.choice(['r','p','s'])
    computer1 = random.choice(['r','p','s'])
    if computer2 == computer1:
        return 'tie'
    if is_win(computer2, computer1):
        return 'computer2 wins!!'
    if is_lose(computer2, computer1):
        return 'computer1 wins!!'
    else:
        return 'it looks like you made a typo! try again'

def is_win(computer2, computer1):
    if (computer2 == "r" and computer1 == "s") or (computer2 == "s" and computer1 == "p") or (computer2 == "p" and computer1 == 'r'):
        return True

def is_lose(computer2, computer1):
    if (computer2 == "s" and computer1 == "r") or (computer2 == "p" and computer1 == "s") or (computer2 == "r" and computer1 == 'p'):
        return True

while True:
    print('welcome to rock paper scissors betting simulator!\n')
    time.sleep(1)
    print('1 = computer1\n')
    time.sleep(1)
    print('2 = computer2\n')
    time.sleep(1)
    beton = str(input('please type 1 or 2 to bet!    \n'))
    coinbet = str(input('you currently have ' + str(int(current_coin)) + ' coins! how much would you like to bet!!\n'))
    if int(str(coinbet)) > int(current_coin):
        print('you dont have that much?\n')
        coinbet = str(input('you currently have ' + str(int(current_coin)) + ' coins! how much would you like to bet!!\n'))
    else:
        print('you betted ' + str(int(coinbet)) + ' !')
    result = play()
    time.sleep(0.1)
    if result == 'tie':
        print('welp! they tied! you have ' + str(int(current_coin)) + ' left!!\n')
    if result == 'computer2 wins!!':
        print('welp, since computer2 won. . .\n')
        if beton == '1':
            print('you lost! you now have ' + str(int(current_coin) - int(coinbet)) + '!!')
            current_coin = current_coin - int(coinbet)
        if beton == '2':
            print('you won! you now have ' + str(int(current_coin) + int(coinbet)) + '!!')
            current_coin = current_coin + int(coinbet)
    if result == 'computer1 wins!!':
        print('welp, since computer1 won. . .\n')
        if beton == '2':
            print('you lost! you now have ' + str(int(current_coin) - int(coinbet)) + '!!')
            current_coin = current_coin - int(coinbet)
        if beton == '1':
            print('you won! you now have ' + str(int(current_coin) + int(coinbet)) + '!!')
            current_coin = current_coin + int(coinbet)      
    if current_coin <= 0:
        print('you have no coins left! what a loser!')
        break