0
私はトリビアゲームを作っています。私はまだPythonには新しいです。ユーザーが手紙とxScore(aまたはb)よりも高い金額を入力しないように、私はtryとexceptの文をどこに置くべきですか? try... except
を使用して、文字(または任意の非整数)を入力するユーザーを防止するためにtryとexcept文を入れてユーザーが入るのを防ぐ場所:文字とそれ以上の量?
class Question:
def __init__(self, question, answera, answerb, answerc, answerd, correct):
self.question = question
self.answers = [answera, answerb, answerc, answerd]
self.correct = correct
def ask(self):
print(self.question)
for n in range(0, 4):
print(" ", n + 1, ")", self.answers[n])
answer = int(input("enter your answer >"))
return answer == self.correct
def right(x):
x * 2
return int(x)
def questions1():
aScore = 10
print('you are able to wager up to', aScore)
bet = int(input('Enter points to wager:'))
question1 = Question("What does the NFL stand for?", "National Football League", "National Fun Live", "No Fun League",
"Narcs Fuzz and Larp", 1)
if question1.ask() == True:
print("You are correct")
aScore += right(bet)
else:
print("incorrect")
aScore -= bet
print('you are able to wager up to', aScore)
bet = int(input('Enter points to wager:'))
question2 = Question("Who won the superbowl last year (2016)", "Atlanta Falcons", "New England Patriots", "Carolina Panthers",
"Toronto Maple Leafs", 2)
if question2.ask() == True:
print("You are correct")
aScore += right(bet)
else:
print("incorrect")
aScore -= bet