我是在 mac 上使用 python 2.5.4 的初学者 python 用户。在过去的几天里,我一直在尝试在 python 中创建游戏股票代码(仅限文本),我几乎完成了,但我在 while 循环中收到“语法错误:无效语法”。这是给我带来问题的代码部分,错误发生在第 5 行,我得到一个 ^ 指向 while 的 e。(我会发布整个内容,但超过 300 行)
while (keep_going ==0):
sell_var = int(raw_input('Please choose what you would like to sell, for grain enter 1, for technology enter 2, for ore enter 3, for construction enter 4, for bonds enter 5, and for trade enter 6, to skip enter any other key'))
if sell_var == 1:
temp_sell = int(raw_input('How many grain stock would you like to sell?')
while (temp_sell > playgrain[x]):
temp_sell = int(raw_input('Please choose a different amount to sell, you do not have that many stock')
playgrain[x] = playgrain[x]-temp_sell
playmoney[x] = playmoney[x] + stock[1] * temp_sell
if sell_var == 1:
temp_sell = int(raw_input('How many technology stock would you like to sell?')
while (temp_sell > playertech[x]):
temp_sell = int(raw_input('Please choose a different amount to sell, you do not have that many stock')
playtech[x] = playtech[x]-temp_sell
playmoney[x] = playmoney[x] + stock[2] * temp_sell
if sell_var == 1:
temp_sell = int(raw_input('How many ore stock would you like to sell?)
while (temp_sell > playore[x]):
temp_sell = int(raw_input('Please choose a different amount to sell, you do not have that many stock')
playore[x] = playore[x]-temp_sell
playmoney[x] = playmoney[x] + stock[3] * temp_sell
if sell_var == 1:
temp_sell = int(raw_input('How many construction would you like to sell?)
while (temp_sell > playconst[x]):
temp_sell = int(raw_input('Please choose a different amount to sell, you do not have that many stock')
playconst[x] = playconst[x]-temp_sell
playmoney[x] = playmoney[x] + stock[4] * temp_sell
if sell_var == 1:
temp_sell = int(raw_input('How many bonds stocks would you like to sell?)
while (temp_sell > playbonds[x]):
temp_sell = int(raw_input('Please choose a different amount to sell, you do not have that many stock')
playbonds[x] = playbonds[x]-temp_sell
playmoney[x] = playmoney[x] + stock[5] * temp_sell
if sell_var == 1:
temp_sell = int(raw_input('How many trade stock would you like to sell?)
while (temp_sell > playtrade[x]):
temp_sell = int(raw_input('Please choose a different amount to sell, you do not have that many stock')
playtrade[x] = playtrade[x]-temp_sell
playmoney[x] = playmoney[x] + stock[6] * temp_sell