首页 > 解决方案 > 音乐游戏程序:我不知道如何授权程序

问题描述

我正在制作一个制作音乐游戏的程序。这是我的登录部分:

def log_in():
Login = False
correctlogin = False
csvfile = open('login_details.csv')
reader = csv.reader(csvfile)

username = input('Please enter your username: ')
password = input('Please enter your password: ')

for row in reader:
    if row[3] == username and row[4] == password:
        correctlogin = True

if correctlogin == False:
    csvfile.close()
    print('incorrect login')
    menu()
else:
    csvfile.close()
    print('Logging on...')
    menu()

这是实际的测验(我知道这有点不专业;我正在整理它):

def quiz():
with open('Questions.csv')as songsFile:
    songsReader = csv.reader(songsFile)
    songs = list(songsReader)

points = 0
lost = False
while not lost:
    song = random.choice(songs)
    artist = song[0]
    title = song[1]
    print('The artist is', artist, 'and the first letter of each word in the song is:')

    words = song[2].split()

    for word in words:
        print(word[0])

    userTitle = input('what is the song: ')

    if userTitle.lower() == title.lower():
        print('Well done, you get three points.')
        points += 3
    else:
        userTitle = input('wrong try again. what is the song: ')
        if userTitle.lower() == title.lower():
            print('Well done, you get one point.')
            points += 1
        else:
            print('Whoops wrong again! The song was',title,'. Game over.')
            lost = True

songsFile.close()
print('you scored', points, 'goodbye.')

如何添加授权以确保用户已登录以进行测验。现在任何人都可以玩。

标签: python

解决方案


推荐阅读