我的石头剪刀布不起作用(Python 2)



所以基本上,无论你输入什么,它都会不断重复选择的问题。是变量错误还是只是循环错误?这真的很烦人,所以有人可以帮我,我将不胜感激。

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

在第一个过程中有一个无限循环。

如果您查看循环条件while status=='yes':,它永远不会结束,直到状态与 yes 不同,这似乎在之后的下一个 while 循环中是可能的。

此外,计算机变量设置为 'cactive',并且永远不会等于 0、1 或 2,因为您希望打印输出。

您应该将第一个循环定义为函数而不是循环。您可以在 https://wiki.python.org/moin/WhileLoop 中了解有关 while 循环的更多信息

最新更新