Python测验根据我的代码不工作?!

时间:2017-11-19 19:11:47

标签: python

我是一名初学者,刚刚开始编写python代码。我正在进行一项多主题测验,这是一个独特的"登录验证,搜索用户名数据库以检查用户名是否已被使用。我遇到的问题是测验中的音乐部分并不真正有效。它是我完成的唯一部分但它似乎没有正常工作。我只是展示代码并解释我遇到的问题。 :)

#Student Quiz
#Started on 16/11
#Questions for music easy
def questionsmusiceasy():
    file=open("Questionsformusic.txt")
name=file.readlines(1)
print (name[0])
score = 0
answer=input()
score=int(0)
if answer=="Sound":
    print("One sec..checking if you got it right :)")
    import time
    time.sleep(3)
    print("Correct!")
    score = score + 1
    print("Your score is now",score,".")
else:
    print("One sec..checking if you got it right :)")
    import time
    print("Sorry but you got it wrong")
    print("Your score is now",score,".")
def menu():
print("\nExcelent. What subjects do you want to select?")
print("\nComputer Science... Music... History?")
subject=input()
if subject==('Computer Science'):
    print("You have selected Computer Science")
    print("\nWhat difficulty would you like")
    print("Easy...\nMedium...\nHard...")
    difficulty=input()
    if difficulty==("Easy"):
       print ("You have selected Computer Science on Easy mode.Please wait...")
       file=open("Studentinfo.txt","a")
       file.write('\nCOMPUTER SCIENCE on....: '+''+difficulty+' ')
       file.close()
       import time
       time.sleep(3)
elif subject==('Music'):
        print("You have selected Music")
        print("\nWhat difficulty would you like")
        print("Easy...\nMedium...\nHard...")
        difficulty=input()
        if difficulty==("Easy"):
             print ("You have selected MUSIC on Easy mode.Please wait...")
             file=open("Studentinfo.txt","a")
             file.write('\nMUSIC difficulty on: '+''+difficulty+' ')
             file.close()
             import time
             time.sleep(3)
             questionsmusiceasy()
elif subject==('History'):
                  print("You have selected History")
                  print("\nWhat difficulty would you like")
                  print("Easy...\nMedium...\nHard...")
                  difficulty=input()
if difficulty==("Easy"):
            print ("You have selected HISTORY on Easy mode.Please wait...")
            file=open("Studentinfo.txt","a")
            file.write('\nHISTORY difficulty on....: '+''+difficulty+' ')
            file.close()
            import time
            time.sleep(3)
if difficulty==("Medium"):
             print ("You have selected HISTORY on Medium mode.Please wait...")
             file=open("Studentinfo.txt","a")
             file.write('\nHISTORY difficulty on....: '+''+difficulty+' ')
             file.close()
             import time
             time.sleep(3)
if difficulty==("Hard"):
    print ("You have selected HISTORY on Hard mode.Please wait...")
    file=open("Studentinfo.txt","a")
    file.write('\nHISTORY difficulty on....: '+''+difficulty+' ')
    file.close()
    import time
    time.sleep(3)
#Subject and quiz part
print("Hello. Lets see if your login is pre-exsisting. Enter your unique login....")
name=input()
if (name) in open('Studentinfo.txt').read():
print ("Hello")
menu()
else:
print("NOPE. Lets create your unique login. Enter your username:")
name=input()
print("And your age please....")
age=input()
realname= name[:3]+age
print ("Ok. Your user name is",realname,".")
file=open("Studentinfo.txt","a")
file.write('\nUsername: '+''+realname+' ')
file.close()
print("\nHold on for a sec")
import time
time.sleep(3)
menu()

当我选择音乐并选择简易模式时,它会执行音乐简易问题定义。但当我完成这个问题时,程序认为我选择了历史简易模式测验选项。我知道这不是真的很深入,但任何帮助都会对我有所帮助

0 个答案:

没有答案