1 import random,time 2 list1=0 3 list2=0 4 for i in range(1,4): 5 print('-------------当前是第' + str(i) + '局' + '-------------') 6 time.sleep(2) 7 list1=random.randint(0,100) 8 list2=random.randint(0,100) 9 a1=random.randint(0,50) 10 a2=random.randint(0,50) 11 while list1>0 and list2>0: 12 # while执行循环体,并会多次重复测试直到测试为假后才执行循环后的其它语句。 13 list1=list1-a2 14 list2=list2-a1 15 print('list1剩余数值:'+str(list1)) 16 print('list2剩余数值:' + str(list2))