【发布时间】:2021-11-22 10:50:15
【问题描述】:
我希望在每次运行循环时继续执行 totalxp 并将其相加,但是我希望每次达到更高等级时停止打印等级 1。
import math
totalxp = 0
rank = 1
while totalxp < 2000:
xpearned = int(input('Enter xp earned last game'))
totalxp = xpearned + totalxp
if totalxp >= 100:
rank = 1
print('You have been promoted to Corporal', rank)
totalxp = totalxp - 100
print(totalxp)
if totalxp >= 300:
rank = rank + 1
print('You have been promoted to Sergeant', rank)
totalxp = totalxp - 300
if totalxp >= 700:
rank = rank + 2
print('You have been promoted to Staff Sergeant', rank)
totalxp = totalxp - 700
if totalxp >= 1500:
print('You have been promoted to Warrant Officer', rank)
print(totalxp)
【问题讨论】:
标签: python while-loop iteration