所以基本上,无论你投入什么,它都会不断重复选择的问题。这是一个变量错误还是只是一个循环错误?它真的很烦人,所以有人请帮助我,我将不胜感激。
import time
from random import randint
#Variable List
# computer - the computer status (choice changes)
# player - the player
# score - the points
# ques - the question
# status - either yes to continue loop no to stop the loop
# ran - the number generated by randint
# cmd - Keeps the config loaded (so keep yes or game will break)
#cactive - allows the randomiser to run and set comp status
status = 'yes'
score = 0
rock = 'r'
paper = 'p'
scissor = 's'
cmd = 'yes'
cmdx = 'yes'
computer = 'cactive'
ran = ["rock", "paper", "scissors"]
#Intro
print "==================================="
time.sleep(1)
print "Welcome To Rock, Paper, Scissors!"
time.sleep(1)
print "Please use lowercase for awnsers."
time.sleep(1)
print "==================================="
time.sleep(1)
raw_input("Are you ready to start? ")
#Awnser Feedback * * * * * * * * * * *
while status=='yes':
ques = input('Chose Rock, Paper, Scissor, Score Or Exit: ')
if computer==0 and ques=='rock': #rock argument
print 'Tie!'
elif computer==0 and ques=='paper':
print 'You Won!'
score = score+1
elif computer==0 and ques=='scissors':
print 'You Lost To Rock'
score = score-1
if computer==1 and ques=='rock': #paper argument
print 'You Lost To Paper'
score = score-1
elif computer==1 and ques=='paper':
print 'Tie!'
elif computer==1 and ques=='scissors':
print 'You Won!'
score = score+1
if computer==2 and ques=='rock': #Scissors Argument
print 'You Won!'
score = score+1
elif computer==2 and ques=='paper':
print 'You Lost To Scissors'
score = score-1
elif computer==2 and ques=='scissors':
print 'Tie!'
#The Game
while status=='yes':
print ques
if ques=='':
print "Please Enter A Command"
if ques=='score': #Score Choice
print "You Have", score, "Points!"
if ques=='cheat': #Score Cheat
score = score+9999999999
print "Cheat Achtivated"
time.sleep(1)
if ques=='clearscore': #Clear Score
score = 0
print "Score Cleared!"
if ques=='killcmd': #Kills Config
cmd = 'no'
print '*ERROR* CMD SHUTDOWN'
if ques=='computer':
print computer
if ques=='ran':
print ran
if ques=='cmd': #Shows the Cmd List
print '------------------------------------------'
print 'cmd - This List'
print 'kill - Shutdown Game'
print 'cheat - Gives Points'
print 'clearscore - Clears The Current Score'
print 'exit'
print 'killcmd - Kills The Config (Not Advised)'
print 'computer - shows what interger the computer is on (debug)'
print 'ran - shows the randint interger (debug)'
print '------------------------------------------'
if ques=='exit':
print 'Thank You For Playing!'
break
#Randomiser * * * * * * * * * * * * *
while status=='yes':
computer = ran[randint(0,2)] #Randint Choice
#if ran==0: #Computer Rock
# computer = 'r'
#elif ran==1:
# computer = 'p'
# if ran==2:
# computer = 's'
if ques=='exit':
print 'Radnomiser Shutdown '
break
答案 0 :(得分:0)
第一次有无限循环。
如果你看一下循环条件while status=='yes':
,它将永远不会结束,直到状态与yes不同,这似乎可能在之后的下一个while循环中出现。
此外,计算机变量设置为'cactive'
,并且永远不会像打印输出那样等于0,1或2。
您应该将此第一个循环定义为函数而不是循环。您可以在https://wiki.python.org/moin/WhileLoop
中了解有关while循环的更多信息