lundi 19 octobre 2020

my rock paper scissors gives me nothing in output (python)

I am new to python and as a practice I'm trying to write a rock paper scissors with it. I triple checked eth but i can't find the problem. I'm using visual studio code console. the msvcrt is for "getch" and I'm not sure about about the random function syntax

problem: when you give it the input number, It doesn't do or write anything despite the program. help me pleaaaaase.

import random
import msvcrt 
##################################################
player_move = " "
system_move = " "
##################################################
def rand(system_move):
    rn = random.randint(1, 3)
    if rn == 1:
        system_move = "Rock"
    elif rn == 2:
        system_move = "Paper"
    elif rn == 3:
        system_move = "Scissors"
    else:
        rand()
    return system_move
##################################################
print("!!! Rock, Paper, Scissors !!!\n\n\n")
###################################################
def playermove(player_move):
    print("What do you want to go with?\n1-Rock\n2-paper\n3-scissors\n")
    temp = msvcrt.getch()
    if temp == '1' or 1:
        player_move = 'Rock'
    elif temp == '2' or 2:
        player_move = 'Paper'
    elif temp == '3' or 3:
        player_move = 'Scissors'
    else:
        print(f"invalid input {player_move}. Try again\n")
        playermove()
    return player_move
###################################################
pm = ' '
sm = ' '
rand(sm)
playermove(pm)
if pm== 'Scissors':
    if sm == "Scissors":
        print(f"System move: {sm}\nIt's a tie!\n")
    elif sm == "Rock":
        print(f"System move: {sm}\nSystem won!\n")
    elif sm == "Paper":
        print(f"System move: {sm}\nYou won!\n")
    else:
        print("Oops! Something went wrong.\n")
        
elif pm == "Paper":
    if sm == "Scissors":
        print(f"System move: {sm}\nSystem won!\n")
    elif sm == "Rock":
        print(f"System move: {sm}\nYou won!\n")
    elif sm == "Paper":
        print(f"System move: {sm}\nIt's a tie!\n")
    else:
        print("Oops! Something went wrong.\n")
elif pm == "Rock":
    if sm == "Scissors":
        print(f"System move: {sm}\nYou won!\n")
    elif sm == "Rock":
        print(f"System move: {sm}\nIt's a tie!\n")
    elif sm == "Paper":
        print(f"System move: {sm}\nSystem won!\n")
    else:
        print("Oops! Something went wrong.\n")

print("Press any key to exit...")
xyz = msvcrt.getch()



Aucun commentaire:

Enregistrer un commentaire