samedi 18 mars 2017

XP Points IF Statement

I got this program that will output their rank based on the number of XP points scored. The problem is when they reach a rank, the XP points get used. e.g. If they reach 20, they become Corporal which is worth a 100 points which leaves them with 100.

The problem is, I can't get the if statement to run with the updated value. e.g. If the reach a particular rank. My IF statement won't recognise the deduction, it will just keep accumulating the points. I tried the change it to the NewXP variable but didn't work.

XP = 0 #Set XP to zero
Rank = 1 #Set rank to one
NewXP = 0

while XP < 2000: #While XP is less than 2000 then this program will run
           point=int(input("Enter XP earnt from last game"))
           XP = XP + point #Adds points entered to the current XP score.
           if XP >= 100 and XP <300:
                 print("You are now a Corporal")
                 NewXP = XP - 100 #This deducts the points for reaching a new rank
                 Rank = Rank + 1 #Adds a new rank number
                 print("You now have",NewXP,"points")
                 continue
           elif XP >=300 and XP <700:
                 print("You are now a Sergeant")
                 NewXP = XP - 300
                 Rank = Rank + 1
                 print("You now have",NewXP,"points")
                 continue
           elif XP >=700 and XP <1500:
                 print("You are now a Staff Sergeant")
                 NewXP = XP - 700
                 Rank = Rank + 1
                 print("You now have",NewXP,"points")
                 continue
           elif XP >=1500:
                 print("You are now a Warrant Officer")
                 NewXP = XP - 1500
                 Rank = Rank + 1
                 print("You now have",NewXP,"points")

Any suggestions would be appreciated.

Aucun commentaire:

Enregistrer un commentaire