python名称定义怎么解决_类的“Python名称错误:未定义名称”

我很难在Python代码中完全定义Questions类。我玩过它,但一直没有运气。在import sys

import random

class Question():

def __init__(self, ques, pa1, pa2, pa3, pa4, correct):

self._q = ques

self._pa1 = pa1

self._pa2 = pa2

self._pa3 = pa3

self._pa4 = pa4

self._correct = correct

def get_ques(self):

return self._q

def get_pa1(self):

return self._pa1

def get_pa2(self):

return self._pa2

def get_pa3(self):

return self._pa3

def get_pa4(self):

return self._pa4

def get_correct(self):

return self._correct

def main():

lst_ques = [

Question("What is our nation's capital", 3, ["Texas", "Virginia", "Washington, D.C.", "New York"]),

Question("How many burrows make up New York city", 4, ["two", "four", "three", "five"]),

Question("In what month does the leap year occur", 1, ["February", "July", "December", "October"]),

Question("What state do the Cowboys football team play for", 2, ["New York", "Texas", "California", "Utah"]),

Question("What's the symbol to Iron", 1 ,["Fe", "Ie", "Ir", "In"]),

Question("Where is Notre Dame", 4 ,["Michigan", "Japan", "Ireland", "France"]),

Question("About how many billion years old is the sun", 3 ,["1", "4", "5", "2"]),

Question("What's the most malleable metal", 2 ,["iron", "gold", "aluminum", "steel"]),

Question("What is short for binary digit", 2 ,["bd", "bit", "bin", "digit"]),

Question("What is the Indiana state bird", 4 ,["robin", "eagle", "finch", "cardinal"]),

]

print('Player #1, please begin.')

i = 1

ca1 = 1

ques_attempted = []

while i<=5:

number = random.radiant(0,9)

if number not in ques_attempted:

print('Question',i)

print(lst_ques[number].get_ques())

print(lst_ques[number].get_pa1())

print(lst_ques[number].get_pa2())

print(lst_ques[number].get_pa3())

print(lst_ques[number].get_pa4())

answer = input('Enter in correct answer: ')

if ques[number].get_correct()==int(ans):

print('Correct!')

ca1+=1

else:

print('Incorrect')

ques_attempted.append(number)

i+= 1

print('Player #2, it is now your turn, please begin.')

i = 1

ca2 = 1

ques_attempted = []

while i<=5:

number = random.radiant(0,9)

if number not in ques_attempted:

print('Question',i)

print(lst_ques[number].get_ques())

print(lst_ques[number].get_pa1())

print(lst_ques[number].get_pa2())

print(lst_ques[number].get_pa3())

print(lst_ques[number].get_pa4())

answer = input('Enter in correct answer: ')

if ques[number].get_correct()==int(ans):

print("Correct!")

i = 1

ca2+=1

else:

print("Incorrect")

ques_attempted.append(number)

print('The final scores are: ')

print('Player #1: ', ca1)

print('Player #2: ', ca2)

if ca1 > ca2:

print('Player #1 is the winner.')

elif ca2 > ca1:

print('Player #2 is the winner.')

else:

print('The final scores are the same, the game is a tie.')

main()

它引发以下异常:

^{pr2}$

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值