startup = 0
r = rock
p = paper
s = scissors

if startup == 0:
    weapon = str(input("Please enter your weapon: Rock, Paper, or Scicors")
        while weapon =! r:
        print("Incorrect choice, please choose again")

Im running python 3.2.2. Im trying to make rock paper scissors. I am trying to get the if statement to startup and print the str weapon. and within that i have a while loop (where the error is on the while) and i want that to print and loop back to the toop if something other than rock, paper, or scissors is inputted. any suggestions?

Recommended Answers

All 4 Replies

The () are not closed properly at line 7, the variables rock, paper, scissors are not defined.

import random

#i think you wanted strings here
r = "rock"
p = "paper"
s = "scissors"

#a list of the weapons
weapons = [r, p, s]

#you need to indent everything you want looped

while True: 

    #raw input is usually used instead of input - see the docs
    user_choice = raw_input("Choose yer weapon [rock/paper/scissors]: ")

    #restarts the loop if the typed response not in the list of weapons
    #using .lower makes it case insensitive
    if user_choice.lower() not in weapons:
        print "%s is not a valid choice!" % user_choice
        continue

    #otherwise break out of the loop
    else:
        break

print "You wield the mystical %s of +1 Awesomeness." % user_choice
computer_choice = random.choice(weapons)
print "A wild programmer appears, swinging a deadly %s!" % computer_choice

You can simplify this as follows (continue and sometimes break often signifies a better logic exists).

import random
 
#i [I] think you wanted strings here
#r = "rock"
#p = "paper"
#s = "scissors"
 
#a list of the weapons
weapons = ["rock", "paper", "scissors"]     ## separate variables are not necessary
 
#you need to indent everything you want looped
user_choice="" 
while user_choice.lower() not in weapons:
 
    #raw input is usually used instead of input - see the docs
    #-----> unless OP is on Python3X
    user_choice = raw_input("Choose yer weapon [rock/paper/scissors]: ")
    if user_choice.lower() not in weapons:
        print "%s is not a valid choice!" % user_choice
 
print "You wield the mystical %s of +1 Awesomeness." % user_choice
computer_choice = random.choice(weapons)
print "A wild programmer appears, swinging a deadly %s!" % computer_choice

The program will choose a weapon (Rock, Paper, Scissors), but its choice will not be displayed until
later so the user doesn‟t see it.
The program will announce the beginning of the round and ask the user for his/her weapon choice
The two weapons will be compared to determine the winner (or a tie) and the results will be displayed
by the program
The next round will begin, and the game will continue until the user chooses to quit
The computer will keep score and print the score when the game end

How do i incorporate these with loops? Im having a hard time trying to figure it out. the code above was all correct but not towards what im shooting for. this is what i have so far

import random
 
#strings here
r = "rock"
p = "paper"
s = "scissors"
 
#a list of the weapons
weapons = [r, p, s]

computer_choice = random.choice(weapons)
user_choice = input("Choose yer weapon [rock/paper/scissors]: ")

if user_choice.lower() not in weapons:
    print ("This is not a valid choice!", user_choice)

while computer_choice != user_choice:
    print("Rock, paper, scissor, shoot!")
    if "rock"and "scissors":
        print("Rock Smashes scissors")
    elif "scissors" and "paper":
        print("Scissors cut paper")
    elif "paper" and "rock":
        print("Paper covers rock")
    break

else:
    print("Tie ,try again...")
    user_choice = input("Choose yer weapon [rock/paper/scissors]: ")
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.