pythonfor循环if中断怎么使用_python在for循环中中断if语句

试试这个:def pTurn(CampLoc, AICampLoc, score, yourHits, cHits):

if yourHits < 5:

#^This line ident is probably the offending line. ;)

hGuess = int(raw_input("Enter a co-ordinate to air-strike: "))

print "Air-striking co-ordinate: %d" % hGuess

for cSpot in AICampLoc:

if hGuess == cSpot:

yConfirMsg = "Kill confirmed!!"

yourHits += 1

score += 100

AICampLoc.remove(hGuess)

break

else:

yConfirMsg= "No casualties"

score = score #You may want to fix this, since the logic doesn't make sense

yourHits = yourHits #Fix this line as well. This is variable value assignment to the same variable.

如果这不起作用,另一件要考虑的事情是,在缩进代码的前导空格时,可能会无意中混合使用制表符和空白。如果是,请将所有选项卡转换为空格。

关于引用的注释。也许你是想回报那些价值观?如果是的话,你需要修正那些逻辑错误。

更新:

如果只需断开一次和一次,则应将break替换为return。

如果没有,那么您应该捕获位置,继续循环执行,并对该信息执行任何操作。#...

values = {}

all_values = []

for cSpot in AICampLoc:

if hGuess == cSpot:

yConfirMsg = "Kill confirmed!!"

yourHits += 1

score += 100

AICampLoc.remove(hGuess)

values['message'] = yConfirMsg

values['hits'] = yourHits

values['score'] = score

values['camploc'] = AICampLoc

all_values.append(values)

else:

yConfirMsg= "No casualties"

#...

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值