Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fixing a code error
#1
I am currently trying to practice python So I tried making a Rock paper scissors game where the player is against a computer but I don't understand how to fix my error in the program, can anyone help?
 
import random
import time
def main():
    print("This is a rock, paper, scissor game")
    
    while answer.upper == 'Y':
        return True
    return False
play_again = True
move_list = {'Rock', 'Paper', 'Scissors'}

def rps():
    print("This is a rock, paper, scissor game")
    time.sleep(3)
    move_list = ['Rock', 'Paper', 'Scissors']
    while play_again == True:
        for comp in move_list.keys():
            user = input('What\'s your hand?: ')
            user = user.capitalize()
            comp = random.choice(list(move_list.keys()))
            if comp == 'Rock' and user == 'Paper':
                print("Computer throws " + comp + " you have thrown " + user + "!")
                print("You Win!")

            elif comp == 'Rock' and user == 'Rock':
                print("Computer throws " + comp + " you have thrown " + user + "!")
                print("It's a draw")
            
            elif comp == 'Rock' and user == 'Scissor':
                print("Computer throws " + comp + " you have thrown " + user + "!")
                print("You Lose!")

            elif comp == 'Scissor' and user == 'Paper':
                print("Computer throws " + comp + " you have thrown " + user + "!")
                print("You Lose!")

            elif comp == 'Scissor' and user == 'Rock':
                print("Computer throws " + comp + " you have thrown " + user + "!")
                print("You Lose!")

            elif comp == 'Scissor' and user == 'Scissor':
                print("Computer throws " + comp + " you have thrown " + user + "!")
                print("It's a Draw!")

            elif comp == 'Paper' and user == 'Paper':
                print("Computer throws " + comp + " you have thrown " + user + "!")
                print("It's a Draw!")

            elif comp == 'Paper' and user == 'Rock':
                print("Computer throws " + comp + " you have thrown " + user + "!")
                print("You Lose!")

            elif comp == 'Paper' and user == 'Scissor':
                print("Computer throws " + comp + " you have thrown " + user + "!")
                print("You Win!")
            else:
                print("You messed up the program dummy")

        
    answer = input("Would you like to play again?: ")


rps()
main()
Error:
Traceback (most recent call last): File "F:\Programing\RPS Game Practice.py", line 62, in <module> rps() File "F:\Programing\RPS Game Practice.py", line 17, in rps for comp in move_list.keys(): AttributeError: 'list' object has no attribute 'keys'
Reply


Messages In This Thread
Fixing a code error - by Twoshawns - May-12-2020, 06:23 AM
RE: Fixing a code error - by ndc85430 - May-12-2020, 07:25 AM
RE: Fixing a code error - by anbu23 - May-12-2020, 07:26 AM
RE: Fixing a code error - by Twoshawns - May-14-2020, 12:23 AM
RE: Fixing a code error - by anbu23 - May-14-2020, 07:54 AM
RE: Fixing a code error - by Twoshawns - May-14-2020, 11:56 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  (python) Can i get some help fixing a English to Morse translator? Pls AlexPython 7 1,647 Sep-12-2022, 02:55 AM
Last Post: AlexPython
  Invalid syntax error - need help fixing calgk01 3 3,332 Feb-23-2021, 08:41 PM
Last Post: nilamo
  Help Fixing Code kianwalters05 5 3,998 May-12-2020, 12:13 PM
Last Post: kianwalters05
  Fixing "PermissionError: [Errno 13] Permission denied" puredata 17 72,822 Mar-09-2020, 03:20 PM
Last Post: syssy
  Fixing the code khanhcao 2 91,922 Feb-06-2020, 07:24 AM
Last Post: buran
  Fixing a problem with file.io ThickTac 2 2,655 Mar-13-2019, 10:13 PM
Last Post: ThickTac
  Fixing indentation issues. MuntyScruntfundle 9 4,249 Feb-02-2019, 05:55 PM
Last Post: snippsat
  Can anyone Please help on fixing this python code to connect and save things on sqlit Roscoes 2 2,933 Mar-06-2018, 04:48 AM
Last Post: Roscoes

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020