求助int()很奇怪的报错

本帖最后由 MeePwn 于 2020-8-23 10:12 编辑

import pygame,sys
from pygame.locals import *
class Trivia:
    def __init__(self,filename):
        self.data = []
        self.current = 0
        self.total = 0
        self.correct = 0
        self.score = 0
        self.scored = False
        self.failed = False
        self.wronganswer = 0
        self.colors = [white,white,white,white]

        file = open(filename,'r')
        trivia_data = file.readlines()
        file.close()

        for text_data in trivia_data:
            self.data.append(text_data.split())
            self.total += 1
    def show_question(self):
        print_text(font1,210,5,'TRIVIA GAME')
        print_text(font2,190,500-20,'Press Keys(1-4) To Answer',purple)
        print_text(font2,530,5,'SCORE',purple)
        print_text(font2,550,25,str(self.score),purple)

        # get correct answer out of data (first)
        self.correct = int(self.data[self.current + 5])

        # dis the question
        question = self.current//6 +1
        print_text(font1,5,80,'QUESTION'+str(question))
        print_text(font2,20,120,self.data[self.current],yellow)

        # respond to correct answer
        if self.scored:
            self.colors = [white,white,white,white]
            self.colors[self.correct-1] = green
            print_text(font1,230,380,'CORRECT!',green)
            print_text(font2,170,420,'Press Enter For Next Question',green)
        elif self.failed:
            self.color = [white,white,white,white]
            self.colors[self.wronganswer-1] = red
            self.colors[self.correct-1] = green
            print_text(font1,220,380,'INCORRECT!',red)
            print_text(font2,170,420,'Press Enter For Next Question',red)
        # display the answer
        print_text(font1,5,170,'ANSWERS')
        print_text(font2,20,210,'1-'+self.data[self.current+1],self.colors[0])
        print_text(font2,20,240,'2-'+self.data[self.current+2],self.colors[1])
        print_text(font2,20,270,'3-'+self.data[self.current+3],self.colors[2])
        print_text(font2,20,300,'4-'+self.data[self.current+4],self.colors[3])

        def handle_input(self,number):
            if not self.scored and not self.failed:
                if number == self.correct:
                    self.scored = True
                    self.score += 1
                else:
                    self.failed = True
                    self.wronganswer = number
  File "c:/Users/Administrator/Desktop/Trivia Game.py", line 37, in show_question    self.correct = int(self.data[self.current + 5])TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'


超过10000字节(帖子限值),我把源代码发到附件了,麻烦大神帮我看下,实在搞不懂为什么报错是 列表了



请先 登录 后评论
  • 0 关注
  • 0 收藏,557 浏览
  • ztruth 提出于 2021-02-28 11:49

相似问题