gpt4 book ai didi

python - 如何在我的音乐游戏中解决这个问题?

转载 作者:行者123 更新时间:2023-12-04 08:10:00 25 4
gpt4 key购买 nike

我目前正在尝试做一个更大规模的项目(就我目前的水平而言),这是一个音乐游戏。在这段代码中一切正常,但有时,当我尝试“打印 (A)”时(可以在代码的最后一行看到),它不会显示歌曲的第一个字母,但有时会显示.我不确定这是为什么。
这是代码:

import songsandartists
import random
import sys
import time

Authorised_players = ("jimmy", "tim", "amy", "bob")
Username = input("Please enter your username: ")
if Username.lower() in Authorised_players:
print("Getting your game ready...")
else:
print("Sorry you are not an authorised player")
sys.exit("""
You are no authorised to play,
Try contacting developers to authorise you :)
EXITING GAME... """)

time.sleep(2)

Random_song = random.choice(songsandartists.Songs)
links = {
"BOP": "DABABY",
"NOBODY'S AROUND": "YNW MELLY",
"LOADING": "CENTRAL CEE",
"LAUGH NOW, CRY LATER": "DRAKE",
}
Reference = {
"DABABY": "BOP",
"YNW MELLY": "NOBODY'S AROUND",
"CENTRAL CEE": "LOADING",
"DRAKE": "LAUGH NOW, CRY LATER",
}
if Random_song in links:
K = links.get(Random_song)
A = Reference.get(K)[0]
print(K)
print(A)

Answer = input("What song do think do you think this artist made that start with the letter above? : ")

points = 0

if Answer.upper() == Random_song in links:
points += 1
print("Correct Answer")
print("You have ", points, " points")
else:
time.sleep(2)
K = links.get(Random_song)
F = Reference.get(K)[0:2]
print(F)
sec_attempt = input("You have one more chance, THINK! : ")
if sec_attempt.upper() == Random_song in links:
print("Well done, You got it this time")
points += 0.5
print("You have ", points, " points")
else:
print("Incorrect, still wrong")

最佳答案

几分钟之内,我意识到了我愚蠢的错误。在我导入的“歌曲和艺术家”文件中,所有歌曲和艺术家的名字都是小写的,我在我的音乐游戏的字典中将它们写成大写,导致它们无法工作,因为在字典中找不到它们。所以基本上,当我试图从字典中搜索并获取“东西”时,它无法因此禁止我从字典中打印任何内容。
多么愚蠢的错误...... smh。

关于python - 如何在我的音乐游戏中解决这个问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66023750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com