python - 音乐游戏程序:我不知道如何授权程序
问题描述
我正在制作一个制作音乐游戏的程序。这是我的登录部分:
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.')
如何添加授权以确保用户已登录以进行测验。现在任何人都可以玩。
解决方案
推荐阅读
- java - 应用程序在测试设备上调试时工作正常,但在发布 apk 中没有,它没有从 firebase 获取 post.class 变量
- javascript - 解析页面时通过另一个脚本调用 JavaScript PostBack
- php - 在codeigniter登录后无法将用户的所有数据保留在会话中
- javascript - 使用 redux 道具更新的 useEffect
- oracle - plsql 过程不是过程或未定义
- perl - Perl - 需要一遍又一遍地调用 system('diff')
- php - 如何使用 PHP 在浏览器控制台上打印
- python - 我正在尝试编写一个“机器人”服务员程序,但我似乎找不到哪里出错了
- java - JavaFX:使 LocalDateTime 触发事件?
- constraint-programming - 如何将两个元素放在同一个序列中?