I forgot to put the spellchecker conditional back in, and when I did I realized "elif" had to be used. Otherwise, it would skip in the array and end with less results instead of 5.
Repeating the post with the adjustment.
Code can be tested at https://www.programiz.com/python-programming/online-compiler/ (Remove the 3 lines of "stuff" on the left on their site, or it might not load properly.)
First attempt at rock, paper, scissors in Python. I was inspired by this post, https://bsky.app/profile/coding.bsky.social/post/3kq7rtxldn42v (Remove the 3 lines of "stuff" on the left on their site, or it might not run properly.)
import random
#import numpy/itertools later (install, run pip, code later)
#a = 1
turnresults = []
choiceplayer = []
scoreplayer = 0
opponentresults = 0
#Do 128 later, 5 for now
while (len(turnresults)<5):
#for a in range(1, 5):
#Have to reindent if using for
choice = input("Enter rock, paper, or scissors: ")
opponent = (random.randint(1,3))
if (choice == "rock") and (opponent == 2):
print("Rock loses to paper \n")
opponentresults = opponentresults + 1
if (choice == "rock") and (opponent == 3):
print("Rock wins to scissors \n")
scoreplayer = scoreplayer + 1
if (choice == "paper") and (opponent == 1):
print("Paper wins to rock \n")
scoreplayer = scoreplayer + 1
if (choice == "paper") and (opponent == 3):
print("Paper loses to scissors \n")
opponentresults = opponentresults + 1
if (choice == "scissors") and (opponent == 1):
print("Scissors loses to rock \n")
opponentresults = opponentresults + 1
if (choice == "scissors") and (opponent == 2):
print("Scissors wins to paper \n")
scoreplayer = scoreplayer + 1
#opponent = str(opponent)
#choice = str(choice)
if (choice == "rock" and opponent == 1) or (choice == "paper" and opponent == 2) or (choice == "scissors" and opponent == 3):
print("SAME!! Try again. \n")
#print ("turnresults = ", turnresults)
#print ("SAME / Turn results = ", turnresults)
elif (choice != "rock" and choice != "paper" and choice != "scissors"):
print("Type rock, paper, or scissors (lower case). \n")
else:
choiceplayer.append(choice)
turnresults.append(opponent)
#print ("opponent's choices: ", turnresults)
#print ("your choices: ", choiceplayer)
#print (turnresults)
print ("Score: YOU ", scoreplayer, " - THEM ", opponentresults)
if (scoreplayer > opponentresults):
print ("***YOU WIN!!!***")
else:
print ("***YOU LOSE!!!***")
#print (len(turnresults))
#if (choice == "rock" or choice == "paper" or choice == "scissors"):
#print("choice is: " + choice)
#opponent = (random.randint(1,3))
#opponent = str(opponent)
#turnresults.append(opponent)
#print (turnresults)
#else:
#print("Type \"rock, paper, or scissors:\"")
#choice = input()
#turnresults.append(opponent)
#print (turnresults)
#a=a+1 #Doesn't work to get 5 turn results
#It doesn't complete 5 successful turn results when the for loop is used
No comments:
Post a Comment