我对编程比较陌生。函数外部的Python变量语法错误?
我一直在试图编写和运行我的第一个程序,我陷入了一个错误。我尝试了几次删除第22行 int(raw_input())中的10然而做了一些其他的调整,但我的技能并不是完全在那里解决了这个问题。
1 Premains = 10 #Remaining points assigned before functions
2
3 #Function designed to see user's overall stats and remaining points
4
5 def print_skills():
6
7 print "Dexterity:" + dex
8 print "Strength:" + str
9 print "IntelligenceL:" + int
10 print "\nYou have %d remaining" % Premain
11
12 #Function called when user selects to edit Dexterity attribute
13
14 def dex_skill():
15 Dpoints = 0
16 print "Great you choose Dexterity!"
17 answer = raw_input("would you like to add or subtract points?\n > ")
18
19 if answer == "add":
20 print "You have: %d points remaining!" % Premains
21
22 numb =(int(raw_input("How many points would you like to add?\n > ")
23
24 Premains = (numb - Premains)
25 Dpoints = numb + Dpoints
26
27 print "Great! you now have: %d Dexterity points!"
28
29 else:
30 print "You choose subtract."
31 #Subtract code goes here. Similiar to above.
32 dex_skill()
〜
这与错误
File "try.py", line 24
Premains = (numb - Premains)
^
SyntaxError: invalid syntax
您在上一行缺少两个紧邻括号。 (外括号集也是不必要的,可能会导致一些奇怪的东西) –
只是一个建议:如果你努力弄清楚像你自己的语法错误这样的事情,而不是在StackOverflow上复制粘贴事物,你会学到更多,更好的东西 – pokemon