这是迄今为止我制作的最大的程序,我的问题是我的程序无法运行,因为未定义变量 cpu。我尝试了不同的方法,但仍然一无所获。这是我的代码,无论如何也可以缩短我的代码吗?我觉得我做了很多重复的台词。我怀疑我的问题出在 def cpu_choice() 中。此外,该程序在完成后似乎没有任何输出。
#This program will execute a Rock,Paper,Scissors Game.
import random
get = int(input('Enter a number 1 to 3 as your choice.\n'))
def cpu_choice():#This function is for the computer to get a option.
list_option = [1 , 2, 3]
cpu = random.choice(list_option)
return(random.choice(list_option))
if cpu == 1:
cpu = "Rock"
if cpu == 2:
cpu = 'Paper'
if cpu == 3:
cpu = 'Scissor'
def compare(cpu,get):
again = 'y'
while again == 'y' or again == 'Y':
if get == cpu:
print('Its a tie!')
again = input('Enter Y or y to play again. Enter N or n to quit.')
if again == 'y' or again == 'Y':
main(cpu)
if again == 'n' or 'N':
again = False
#Checks to see if it is a tie
elif cpu == 'Rock' and get == 'Scissor':
print('You win!')
again = input('Enter Y or y to play again. Enter N or n to quit.')
if again == 'y' or again == 'Y':
main(cpu)
if again == 'n' or 'N':
again = False
#Compares when CPU picks Rock.
elif cpu == 'Rock' and get == 'Paper':
print('You lose.')
again = input('Enter Y or y to play again. Enter N or n to quit.')
if again == 'y' or again == 'Y':
main(cpu)
if again == 'n' or 'N':
again = False
慕容708150
偶然的你
繁华开满天机
相关分类