我是python的新手,我正在尝试制作一个Runescape计算器,好吧,因为我很无聊。无论如何,我熟悉urllib模块,我用它来在线检索帐户信息。这是我的代码:
import urllib
input("Rune Scape EOC Calcalator")
print ("Please Input Your Skills or Enter Your Username (If You Enter Your")
print ("Username All Your F2P Skills Have To Be Level 15) :")
UsrSkill = input("Do You Want To Enter Your Skills Or Your Username? ")
if UsrSkill == "Skills" :
DefSkill = int(input("Defence :"))
StrSkill = int(input("Strength :"))
AttkSkill = int(input("Attack :"))
RngeSkill = int(input("Ranged :"))
MageSkill = int(input("Magic :"))
SmmnSkill = int(input ("Summoning :"))
if UsrSkill == "Username" :
usrname = input("What Is Your Username")
j = ("http://xptracker.com/index.php?username=",usrname"&Submit=GO&comparename=&mode=regular")
with urllib.request.urlopen(J) as resp :
data = resp.read()
resp.code
'Defence' in data is DefSkill
'Strength' in data is StrSkill
'Attack' in data is AttkSkill
'Ranged' in data is RngeSkill
'Magic' in data is MageSkill
'Summoning' in data is SmmnsSkill
x = [StrSkill, AttkSkill, RngeSkill, MageSkill, SmmnSkill]
OfnsiveSkill = max(x)
CbLvl = OfnsiveSkill + DefSkill + int(2)
print ("You Are Level:", CbLvl)
这是错的:它不断出现一条错误信息:
Invalid Syntax
... usrname"&Submit=GO&comparename=&mode=regular**"**)
当我拿出“用户名”时,它会出现这个:
x = [StrSkill, AttkSkill, RngeSkill, MageSkill, SmmnSkill]
NameError: name 'StrSkill' is not defined
从我对失败的了解〜很多〜我认为这是由于我的判断。 谢谢。 帮助
答案 0 :(得分:1)
你的代码有几个错误,我建议从头开始而不是修复它们。我问你
后,我会为你解释is
is
可能不会按照您的想法执行,它用于比较两个变量。
is
是一个比较器语句,它返回第一个对象是否与第二个对象相同的实例,例如a is a
将返回True
,因为它们是完全相同的对象。
>>>2.0 is 2
False
>>>2.0 == 2
True
答案 1 :(得分:0)
这个
j = ("http://xptracker.com/index.php?username=",usrname \
"&Submit=GO&comparename=&mode=regular")
最有可能是:
j = ("http://xptracker.com/index.php?username=" + usrname + \
"&Submit=GO&comparename=&mode=regular")
答案 2 :(得分:0)
很棒的代码,phew ......但是,有一些错误,如:
j = ("http://xptracker.com/index.php?username=",usrname"&Submit=GO&comparename=&mode=regular")
尝试以另一种方式构建字符串j
。例如,在.format()的帮助下:
j = "http://xptracker.com/index.php?username={username}&Submit=GO&comparename=&mode=regular".format(username=usrname)
正如您所看到的,我们可以省略括号并使用{username}作为关键字占位符,可以使用正确的字符串.format()填充此类username=username
另外,我认为在本节中你丢失了缩进:
with urllib.request.urlopen(J) as resp :
data = resp.read()
resp.code
如果用户选择输入“用户名”而不是“技能”,则StrSkill
可以是未定义的。