<p>我想做一个游戏,玩家每次玩的时候都会从ini文件中的值中扣除.5。但是我总是出错,我不知道该怎么办。这是我的密码。别担心这些评论,这些是给我的,我稍后会关闭while循环。这只是代码的一部分。顺便说一句,代码起作用了,只是不是这个。谢谢。在</p>
<pre><code>def rerun():
import ConfigParser
from ConfigParser import ConfigParser
parser = ConfigParser()
parser.read('Game.ini')
PlrMny = parser.get('money_value', 'Amount')
#config = ConfigParser.ConfigParser()
configFile = open("C:\Python27\Game.ini", "w")
#config.read(configFile)
#valueamount = config.getfloat("section","starting_value")
print "You will be given a $10 starting amount. Each game costs $.50 to play and is
deducted when you input the first value."
print "\nGetting one match gives $1 and the output is multiplied by 2 for each extra
match."
print "\nCurrent Amount =",PlrMny,
def gamble():
PlrMny = parser.get('money_value', 'Amount')
import random
import sys
number1 = random.randint (1, 20)
number2 = random.randint (1, 20)
number3 = random.randint (1, 20)
number4 = random.randint (1, 20)
number5 = random.randint (1, 20)
def input():
c = 0
print "\n\n\n\nTry guess what five numbers the computer will guess. Type '100'
in any of the inputs to close program prematurely"
print "Money =",PlrMny,
#parser.set("money_value", "Amount",10000)
#parser.write ('Game.ini')
while True:
try:
User11 = int(raw_input( "\n\nNumber 1 : "))
parser.set('money_value','Amount',float(PlrMny) - .5)
parser.write (configFile)
str(PlrMny)
if User11 < 1:
print "Error"
elif User11 == 100:
sys.exit()
elif User11 > 20:
print "Error"
else:
break
except ValueError:
print "Error"
</code></pre>
<p>这是错误:</p>
^{pr2}$