I am trying to figure out if there is a way to add together the outputs of a while loop. Here is the code for the loop I have:
charlvl = input("Character level? ") while charlvl != 0: mobxp = (charlvl*5) + 45 a = int((8*charlvl*mobxp)/100)*100 charlvl = charlvl - 1 print "At level", charlvl,"you will have earned", a, "xp total."
What I am trying to do is have someone (me) put in their character level, then have it calculate how much XP that level will take (the mobxp = (charlvl*5) + 45 & a = int((8*charlvl*mobxp)/100)*100 line do that), and every level's XP below that level (lowest level is 1). Then, if it is possible, add those outputs together.
If you want to compile and run this, the output for "character level? 2" should be 800 on first run and 400 on second run. When recoded I the hoped for output would be one line and would read something like "At level 2, you will have earned 1200 xp."
Notes: 1. Don't worry about the character level being negative, if someone is dumb enough to put in a negative number, they deserve the output. 2. I realize a while loop probably won't do that, but the tutorials I have read for python don't show me any other way to do it :( 3. The starting level is 1, there is no need to calculate a level up for level 0 as it doesn't exist. 4. If you need something further explained, please ask and I will see what I can do.
hm...I wish I could edit my post, oh well. As a note, if you run the above code as it stands, the output is "at level 1..." and "at level 0..." this is because I am new to programming and forgot that computers count from zero :p. My bad.
Good job man, just for future reference though, please indent your code coz its really hard to go through and people would probably get frustrated and leave it as if they can't read your code. or [pre] def func: statement1 or [/pre]( code in [] paranthesis or pre in[] closed by [/]