Python Forum
Good enough? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: Code Review (https://python-forum.io/forum-46.html)
+--- Thread: Good enough? (/thread-31833.html)



Good enough? - blacksword - Jan-05-2021

Hi, im new to this whole programming thing. So for my first uni project we had to make a rock paper scissors game. Would this be acceptable though? Or should i expand it somehow?

import random
import time

score_player = 0
score_comp = 0
play = True

def comp():
    global comp_ans
    mylist = ["r", "p", "s"]
    comp_ans = random.choice(mylist)

def winner():
    global score_comp
    global score_player 

    # Setting up logic for winning for player and comp
    if answer == "r" and comp_ans == "s":
        print("\n-------------------" + "        "f"score: {score_player}, losses : {score_comp}")
        print(f"{answer} vs {comp_ans}")
        print("-------------------\n")
        print("Player wins!")
        score_player += 1
    elif answer == "s" and comp_ans == "r":
        print("\n-------------------" + "        "f"score: {score_player}, losses : {score_comp}")
        print(f"{answer} vs {comp_ans}")
        print("-------------------\n")
        print("Comp wins!")
        score_comp += 1

    elif answer == "s" and comp_ans == "p":
        print("\n-------------------" + "        "f"score: {score_player}, losses : {score_comp}")
        print(f"{answer} vs {comp_ans}")
        print("-------------------\n")
        print("Player wins!")
        score_player += 1
    elif answer == "p" and comp_ans == "s":
        print("\n-------------------" + "        "f"score: {score_player}, losses : {score_comp}")
        print(f"{answer} vs {comp_ans}")
        print("-------------------\n")
        print("Comp wins!")
        score_comp += 1

    elif answer == "p" and comp_ans == "r":
        print("\n-------------------" + "        "f"score: {score_player}, losses : {score_comp}")
        print(f"{answer} vs {comp_ans}")
        print("-------------------\n")
        print("Player wins!")
        score_player += 1
    elif answer == "r" and comp_ans == "p":
        print("\n-------------------" + "        "f"score: {score_player}, losses : {score_comp}")
        print(f"{answer} vs {comp_ans}")
        print("-------------------\n")
        print("Comp wins!")
        score_comp += 1

    elif answer != "p" and answer != "r" and answer != "s":
        print("\n-------------------" + "        "f"score: {score_player}, losses : {score_comp}")
        print("Not a valid input!")

    else:
        print("\n-------------------" + "        "f"score: {score_player}, losses : {score_comp}")
        print(f"{answer} vs {comp_ans}")
        print("-------------------\n")
        print("Tied!")

def run():
    global answer
    comp()   
    answer = input("\nChoose between: r, p or s: \n")
    answer = answer.lower()
    winner()


while play:
    run()

    if answer != "p" and answer != "r" and answer != "s":
        pass
    else:
        answer = input("Would you like to play again? yes or no?: \n")
        answer = answer.lower()
    
        if answer == "yes" or answer == "y":
            pass
        else:
            print("Thank you for playing!\n")            
            time.sleep(1)
            break



RE: Good enough? - ndc85430 - Jan-06-2021

Wouldn't those be questions for the person setting the assignment, rather than some random people on the Internet?