Python Forum
The Python Book altered rock paper scissors
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The Python Book altered rock paper scissors
#1
#!U:\Pycharm\Game.py
# Rock Paper

import random
import time

dragon = 1
spear = 2
human = 3
names = {dragon: "Dragon", spear: " Spear", human: "Human"}
rules = {dragon: human, spear: dragon, human: spear}
player_score = 0
computer_score = 0


def start():
print "Want to play a game?"
while game():
pass
scores()


def game():
player = move()
computer = random.randint(1,3)
result(player, computer)
return play_again()


# noinspection PyUnreachableCode,PyUnreachableCode
def move():
while True:
print
player = raw_input("Dragon = 1\nSpear = 2\nHuman = 3\nPick a number already, peon!: ")
try:
player = int(player)
if player in (1,2,3):
return player
except ValueError:
pass
print "You really can't count? Enter a number 1, 2 or 3"



def result(player, computer):
print "1..."
time.sleep(1)
print "2..."
time.sleep(1)
print "3!"
time.sleep(0.5)

print "Computer threw [0]!".format(names[computer])

global player_score, computer_score
if player == computer:
print "can't even beat an AI."
else:
if rules[player] == computer:
print "Winner Winner Chicken Dinner."
player_score += 1

else:
print "The computer just beat you, Skynet is upon us."
computer_score += 1


def play_again():
answer = raw_input("want to come and play? y/n: ")
if answer in ("y", "Y", "yes", "Yes", "of course!"):
return answer
else:
print "Thank you very much for playing Aaron Sans game. get reked noob!"


def scores():
global player_score, computer_score
print "HIGH SCORES "
print "Player: ", player_score
print "Computer: ", computer_score
if __name__ == '__main__':
start()


****************************************************

Okay so when I run the file it in python

Want to play a game?

Dragon = 1
Spear = 2
Human = 3

Pick a number already, peon!:

as soon as I input any number, it loops and says the same text.
I think the input is incorrect as Pycharm stats noinspection PyUnreachableCode,PyUnreachableCode if so how do I change the code?
What am I doing wrong?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I attempted to make a rock paper scissors bot for homework Intellectual11 3 2,866 Jun-24-2021, 08:00 PM
Last Post: deanhystad
Question Rock, paper, scissors spelling error banidjamali 6 3,139 Jan-19-2021, 02:51 PM
Last Post: banidjamali
  Rock, Paper, Scissors Game kramon19 2 5,291 Jan-10-2020, 08:18 AM
Last Post: perfringo
  I need help with a python Rock Paper Scissors game urgently. Riff_Raff 3 5,753 Dec-05-2018, 09:13 PM
Last Post: nilamo
  Rock, Paper, Scissors Advanced that saves, loads, and keeps statistics EvanCahill 0 5,163 Jul-21-2018, 07:32 PM
Last Post: EvanCahill
  Rock Paper Scissors Warmlawpk441 4 4,972 Oct-11-2017, 10:55 AM
Last Post: gruntfutuk
  Rock paper scissors game samiraheen 3 6,305 Oct-03-2017, 07:07 PM
Last Post: buran
  HELP---problems with rock paper scissors games kalt91 2 4,069 Sep-15-2017, 04:51 PM
Last Post: micseydel
  Rock, Paper, Scissors game help.. hentera 3 4,998 May-19-2017, 10:56 PM
Last Post: ichabod801
  Rock Paper Scissors game codeobri 3 13,343 Apr-28-2017, 01:02 AM
Last Post: codeobri

Forum Jump:

User Panel Messages

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