Python programming

I have to write a Rock Paper Scissors game on python for my class but I can't figure out what I'm doing wrong if anyone wants to help me figure out what I'm doing wrong that would be great thanks

Attached: img.jpg (352x480, 40K)

[Print Screen] then [Ctrl+V] in ms paint

thanks that fixed it

The problem is that you're using python

How do I make an inventory database?

You gotta have rock, paper, and scissor factories or else you're gonna run out of materials.

f00 = "Item1"
f01 = "Item2"
f02 = "Item3"
f03 = "Item4"
f04 = "Item5"
f05 = "Item6"
f10 = "Item7"
f11 = "Item8"
f12 = "Item9"
f13 = "Item10"
f14 = "Item11"
f15 = "Item12"
v00 = 0
v01 = 0
v02 = 0
v03 = 0
v04 = 0
v05 = 0
v10 = 0
v11 = 0
v12 = 0
v13 = 0
v14 = 0
v15 = 0

def IncrementItem1():
v00 = v00 + 1

def IncrementItem2():
v01 = v01 + 1
....

def pickupItem():
if (pickedUpItem == f00):
statement("IncrementItem1")
elif (pickedUpItem == f01):
statement("IncrementItem2")
....

Lamer.

if you're having trouble figuring out how to take a screenshot, you might want to start somewhere else

Bit of coding practices advice. If you have a method that returns a value, you don't need to use else or even elif.

if (statement1)
return value1

if (statement2)
return value2

if (statement3)
return value3


That way your code stays linear and doesn't fork off into different branch possibilities.

google: happy path

Actually I think have a single return per function is better, even if it adds another line.

Your player() and computer() aren't being called to get the throws, and player() isn't even returning anything. Focus on getting the player throw and printing it for now.

...

I know fuck all about Python, but how are you calling computer() ?

import random

while True:
userThrow = input("Throw [R]ock, [P]aper, or [S]cissors (Q to quit.) ")
userThrow = userThrow.upper()
if userThrow == "Q":
break
throw = random.randint(1, 3)

print("Computer throws: ", end="")

if throw == 1:
print("ROCK.")
if userThrow == "R":
print("Tie.")
elif userThrow == "P":
print("You win!")
else:
print("You lose.")

if throw == 2:
print("PAPER.")
if userThrow == "R":
print("You lose.")
elif userThrow == "P":
print("Tie.")
else:
print("You win!")

else:
print("SCISSORS.")
if userThrow == "R":
print("You win!")
elif userThrow == "P":
print("You lose.")
else:
print("Tie.")


Git gudder.

holy useless branches, batman

from random import choice
player = ''
while player != 'q':
outcomes = ['tie', 'you lose', 'you win']
player=input("Throw [R]ock, [P]aper, or [S]cissors (Q to quit.) ").lower()
if player != 'q':
computer=choice('rps')
print('computer chose {}'.format(computer))
print(outcomes[(player!=computer)+(computer+player in 'rpsr')])

(1/2)

#!/usr/bin/env python3


from enum import Enum
from random import choice


class Result(Enum):
WIN = 1
LOSE = 2
DRAW = 3


class Sign(Enum):
ROCK = 1
PAPER = 2
SCISSORS = 3


def get_result_from_signs(sign1, sign2):
return {
Sign.ROCK: {
Sign.ROCK: Result.DRAW,
Sign.PAPER: Result.LOSE,
Sign.SCISSORS: Result.WIN,
},
Sign.PAPER: {
Sign.ROCK: Result.WIN,
Sign.PAPER: Result.DRAW,
Sign.SCISSORS: Result.LOSE,
},
Sign.SCISSORS: {
Sign.ROCK: Result.LOSE,
Sign.PAPER: Result.WIN,
Sign.SCISSORS: Result.DRAW
}
}.get(sign1, {}).get(sign2)


class Player(object):
score = 0

def __init__(self, name):
self.name = name

def get_sign(self):
while True:
try:
return Sign[input("Choose 'rock', 'paper', or 'scissors': ").upper()]
except KeyError:
print("Please enter a valid option")


class AI(object):
name = "AI"
score = 0

def get_sign(self):
return Sign[choice(["ROCK", "PAPER", "SCISSORS"])]


def rps_round(player1, player2):
sign1 = player1.get_sign()
sign2 = player2.get_sign()

result = get_result_from_signs(sign1, sign2)

msg = None

if result == result.WIN:
msg = "Player {} won that round ({} vs. {})".format(player1.name, sign1, sign2)

player1.score += 1
elif result == result.LOSE:
msg = "Player {} won that round ({} vs. {})".format(player2.name, sign1, sign2)

player2.score += 1
elif result == result.DRAW:
msg = "Draw! ({} vs. {})".format(sign1, sign2)

print(msg)

Your problem is that
print(rps_outcome())

Should be
print(rps_outcome(computer (), player()))

>taking class with programming assignment
>taking a picture of a screen
just give up.

You are comparing a number to a string, arent you?

This should work OP
Looks like it might work but I'm too drunk and too unfamiliar with all things python (yea I know) to tell for certain just by looking a it
This

After you fix your program, try it again, but this time use modular arithmetic.
Rock - 0
Paper - 1
Scissors - 2
Computer's input - m
Your input - n
If n = (m + 1) mod 3, WIN.
Else, if n = m, TIE.
Else, LOSE.

There is just one problem, you are using jewthon, use J++ u dumbfag

looking forward to 2/2 of this enterprise af RPS program

not op but can you explain how the last line in this works

from random import choice

# OPTIONS = {
# 'rock': {'scissors', 'lizard'},
# 'paper': {'rock', 'spock'},
# 'scissors': {'paper', 'lizard'},
# 'lizard': {'spock', 'paper'},
# 'spock': {'rock', 'scissors'}
# }

OPTIONS = {
'rock': {'scissors'},
'paper': {'rock'},
'scissors': {'paper'}
}

CHOICES = list(OPTIONS.keys())


def get_result(player, computer):
if computer == player:
return 'tie'
elif computer in OPTIONS[player]:
return 'you win'
return "you lose"


def main():
player = input('choose from {} '.format(CHOICES))
computer = choice(CHOICES)
print("computer threw {}".format(computer))
print(get_result(player, computer))

if __name__ == '__main__':
main()


this one can be arbitrarily expanded

> print(outcomes[(player!=computer)+(computer+player in 'rpsr')])

> int(player!=computer)
this is 0 in the event of a tie and 1 otherwise


> int(computer+player in 'rpsr')
if the characters that computer and player chose are in rpsr, this is 1 otherwise, it's 0

rpsr because
computer=[r]ock player=[p]aper is a win
computer=[p]aper player=[s]cissors is a win
etc

> (player!=computer)+(computer+player in 'rpsr')
this automatically casts the bools to ints, and gives
0 points if player==computer
1 point if player != computer and the player loses the exchange (see above)
2 points if player != computer and the player wins the exchange (see above)

> outcomes = ['tie', 'you lose', 'you win']
> outcomes[(player!=computer)+(computer+player in 'rpsr')]
this accesses the element of the array that the exchange resulted in, 0 for tie, 1 for loss, 2 for win

nvm i guess i figured it out
false + false = 0 ?
false + true = 1
true + true = 2
and you are checking if the player had a different option than the computer and then if the computer's choice is lower in the ranking of rps r

What's wrong with Python?

Hey OP, seems like people in this thread have given you working solutions already but I'll point out your specific mistakes if you're interested:

1. There's a space between randint and the brackets
2. In the computer function you're using 'computer' in the if statements. 'computer' is not a variable, so it doesn't exist - for functions you need to use functionName() (so computer()). However even then this isn't what you want here, you want the 'throwcomputer' variable. I don't really know the reasoning behind trying to call the function again there.
3. In the function rps_outcome, you haven't actually put the variables throwcomputer and throwplayer into the function by putting them into the brackets as you've defined it. When you define a function, the values that goes in those first brackets are new varibles that exist only inside the function (so you can call them whatever you want), and then you asign values to these varibles every time you call the function - when you type rps_output() at the bottom you want to type rps_output(throwcomputer, throwplayer). That's when python will actually use the variables you've defined elsewhere in the script. However, even then in that case this isn't going to work, as both of those variables were defined inside a function, so they can't be used outside of it (because of variable scopes, google it), so to fix this you would define both varibles at the top of the script if you wanted to use them that way. I don't think it's those variables you even want though as they're just the random numbers you're using to get the rock, paper or scissor values, so instead in this case you want what's being returned by the two functions computer and player. In this case, you can write rps_output(computer(), player()). For the record though, you don't need a function just for input, that can have it's own variable, and inputs already come as strings so you don't need to convert to one either.

Hope this helps.

>big bang referance

You're not calling the functions. Put

computer ()

Before your last print line.

>outcomes inside the while loop

throw = input("What do you throw? (R)ock, (P)aper, (S)cissors: ")

if throw == "R":
print("paper. you lose!")
else if throw == "P":
print("scissors, you lose!")
else if throw == "S":
print("rock, you lose!")

outcomes = ['rock', 'paper', 'scissors']
print "Please enter 'rock', 'paper', or 'scissors': "
humanP = gets.chomp
pcP = Random.new.rand(3)
print "The computer is #{outcomes[pcP]}. You are #{humanP}. "
humanP = outcomes.index humanP
print "Tie!\n" if humanP == pcP
print "You " + (humanP == (pcP + 1) % 3 ? "win" : "lose") + "!\n"

>if __name__ == '__main__':
> main()
I'm glad I stuck with Ruby.

>throwcomputer = random.randint(0,2)
>if computer == 0
this is where you made mistake, you assign the random number to 'throwcomputer' variable but work with 'computer' variable (which is also name of function, avoid such naming collisions)

>rps_outcome(a, b)
but calling without arguments

player() function returns nothing

total trash structure of program, is it your first day?