下面是api的wiki:https://github.com/ppy/osu-api/wiki
所以我建立这个程序来比较等级,所以我抓取用户名和它们的等级,现在我被困在如何存储信息上,然后将两者相减以得到差别!你知道吗
抱歉,我只写了大约2-4周的代码,我肯定这是一个超级简单的东西,我的代码可能是超级恶心。你知道吗
我目前拥有的代码:
def player1():
payload = {'k': 'myapi', 'u': input()}
r = requests.get('https://osu.ppy.sh/api/get_user', params=payload)
player = r.json()[0]
return (player["pp_country_rank"])
player = player1()
print(player)
print('Enter a second Username')
def player2():
payload = {'k': 'myapi', 'u': input()}
r = requests.get('https://osu.ppy.sh/api/get_user', params=payload)
player = r.json()[0]
return (player["pp_country_rank"])
player = player2()
print(player)
感谢奥尔德里克的帮助,奥斯汀意识到我犯的错误。。。初学者的东西。你知道吗
这就是我的代码现在的样子,我得到的区别是,我有一些小错误,比如每当player\u 1比player高很多的时候,它就会返回一个负整数,清理代码,因为有些代码和我从Austin那里得到的是毫无意义的,每当我可以把它都放在同一个函数中。但至少我是有目的的!:)
当您有一个调用并返回结果的函数时,您可以将其保存到一个新变量中供以后使用:
这意味着在以后的代码中,您可以将其用于其他用途。另外,当您创建一个函数时,您可以定义在函数中使用的变量,这些变量可以在调用函数时传递。对于您的示例,您可能希望传递“username”变量,而不是在有效负载中进行输入。你知道吗
因为我没有访问你的API的权限,所以我创建了一个修改过的示例,下面有注释,应该以与你得到的回报类似的方式来做事情。如果您在API服务器上发布一个JSON示例,那么拥有一个工作示例就更容易了。你知道吗
相关问题 更多 >
编程相关推荐