这里我想退出if块,但不想使用系统出口(),因为它将终止程序。我有几行要在末尾执行,因此只想退出if块。
无法使用break,因为它标记错误“break outside loop”
--已编辑--
在这里,我希望程序在“if(retry==3)”第55行退出块,并在末尾打印行。然而,直到被使用才发生系统出口()完全退出程序import random
import sys
loop = ''
retry = 0
loop = input('Do u want to play lottery ? yes/no : ')
if loop !='yes':
print('Thank you!! visit again.')
sys.exit()
fireball = input('Do you want to play fireball ? yes/no : ')
lotto_numbers = sorted(random.sample(range(0,4),3))
fireball_number = random.randint(0,3)
while loop == 'yes':
user_input1 = int(input('pls enter the first no: '))
user_input2 = int(input('pls enter the second no: '))
user_input3 = int(input('pls enter the third no: '))
print ('your numbers are : ' , user_input1,user_input2,user_input3)
def check():
if lotto_numbers != [user_input1,user_input2,user_input3]:
return False
else:
return True
def fbcheck():
if lotto_numbers == [user_input1,user_input2,fireball_number]:
return True
elif lotto_numbers == [fireball_number, user_input2, user_input3]:
return True
elif lotto_numbers == [user_input1, fireball_number, user_input3]:
return True
else:
return False
retry += 1
result=check()
if (result == True):
print ("Congratulations!! You won!!")
else:
print ("Oops!! you lost.")
if (fireball == 'yes'):
fb_result=fbcheck()
if (fb_result == True):
print ("Congratulations, You won fireball!!")
else:
print ("Sorry you lost fireball.")
print ('No of retries remaining : ' , (3 - retry))
if (retry == 3):
sys.exit()
loop=input('Do you want to try again? yes/no : ')
continue
else:
pass
print ("Winning combo : ",lotto_numbers)
if (fireball == 'yes'):
print ('fireball no : ' , fireball_number)
print('Thank you!! visit again.')