Dec-01-2021, 05:29 PM
So, essentially, I am trying to make a simple program in python 3 (using CodeHS, if that matters) for a theoretical RPG concept. Basically, it is supposed to take the level increase (which can be decided randomly or by user input) and assign a stat point to a random stat, where the theoretical character gets 1 stat point per level. No matter what I do, the number of levels is inconsistent with the stat values, so a "character" who levels up 43 times might only get 41 stat points. The system that generates stats is in a for loop using the level value as the repeated amount of times. I wish I could provide more information, but I am unaware of what is causing this issue or how to recreate it. I have tried creating multiple "repair sequences". Communication is not my strong point, so I will provide the code (with comments on what each segment does) in all of its glory.
I am new to the forums so i apologize if my formatting was incorrect. As for operating system, I have tried this on both ChromeOS and Windows 10. My general question is, how can I make the two output values match consistently?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
import random # This area provides instructions for the user. print ( "Welcome to the Spellcrest Beta Stat Assigner." ) print ( "infer your character or enemy is at level 1, and" ) print ( "choose how many levels you want to add. Or leave it random!" ) print ( "the minimum level gain is 1, and the max is 100. No decimals." ) print ( "starting from other levels is planned... some day." ) print ("") print ( "Choose Level? (1 for yes, 2 for random level within range." ) # User Input determines how the amount of points are chosen. randomcheck = int ( input ( "Anything else will randomize it between all possible values [1-100]): " )) # Choosing "1" will let the user select the level. if randomcheck = = 1 : level = int ( input ( "How many levels are gained?: " )) print ("") print ( "level gain: " ) print (level) # Error messages prevent going out of intended range. if level > 100 : print ( "Level cannot be over 100. Please try a number between 1 and 100." ) quit() if level = = 0 : print ( "Why are you here if you aren't gaining any levels? (Please try a number between 1 and 100.)" ) quit() if level < 0 : print ( "Even if losing levels was possible, this program assumes the character is gaining points" ) print ( "from level 1." ) print ( "Please try a number between 1 and 100... a positve one." ) quit() """ Choosing 2 will ask the user to input a level range, and randomly select a number within that range. """ if randomcheck = = 2 : levellow = int ( input ( "Lowest Possible Level Gain: " )) levelhigh = int ( input ( "Highest Possible Level Gain: " )) """ it was mandatory that I made this error code before the level value was assigned, since it would have triggered an error. """ if levellow > levelhigh: print ("") print ( "People like you are why I have to make these error messages." ) print ( "Lowest possible level must be lower than highest possible level gain" ) print ( "they can be equal, but you'd be better off using 1 at the start of the program." ) quit() """ inferring that everything goes well, this will generate a random level within the range of the numbers the user input. """ level = random.randint(levellow, levelhigh) """ here I put various easter eggs and error messages. Speaking of easter eggs, how did you get in here? (This doesn't apply to forum users reading a thread I may or may not have made in the event I can't figure out my calculation error that may or may not still be present) """ if levellow < = 0 : print ("") print ( "Invalid lowest possible level gain." ) if level < = 0 : print ( "Your value was" , level, ", so the program will end." ) quit() if level > 0 : print ( "...However, your value was" , level, ", so I guess I'll let it slide." ) if levelhigh > 100 : print ("") print ( "Invalid highest possible level gain." ) if level > = 100 : print ( "Your value was" , level, ", so the program will end." ) quit() if level < 100 : print ( "...However, your value was" , level, ", so I guess I'll let it slide." ) if levellow = = levelhigh: print ( "You goof, why didn't you just pick 1 at the beginning?" ) # Tells the user the randomly selected level gain. print ("") print ( "level gain: " ) print (level) # Conditional easter egg. if levellow = = levelhigh: print ( "big surprise." ) """ If the user chooses anything else, the program will randomly select a number. """ if randomcheck > 2 or randomcheck < = 0 : level = random.randint( 1 , 100 ) print ("") print ( "level gain: " ) print (level) """ defining stat values. """ HP = 0 MP = 0 ME = 0 ATK = 0 SPD = 0 """ This little system here will randomly generate a value and assign a point to a stat determined by that value. I felt really smart for coming up with this but I'm likely not the first or the last. """ print ("") print ( "assigning stats..." ) print ("") for i in range (level): statpoint = random.randint( 1 , 100 ) if statpoint in range ( 1 , 20 ): HP = HP + 1 if statpoint in range ( 21 , 40 ): MP = MP + 1 if statpoint in range ( 41 , 60 ): ME = ME + 1 if statpoint in range ( 61 , 80 ): ATK = ATK + 1 if statpoint in range ( 81 , 100 ): SPD = SPD + 1 """ This "total" variable is the total points assigned, used to check if the level and total points assigned are consistent. """ total = HP + MP + ME + ATK + SPD print ( "Complete!" ) """ Notifies the user what points were assigned to what stats. """ print ("") print ( "Health increased by" , HP) print ( "Magic Power increased by" , MP) print ( "Magic Energy increased by" , ME) print ( "Attack increased by" , ATK) print ( "Speed increased by" , SPD) print ("") """ Notifies the user of the comparison between the level and total points. Ideally, this error message shouldn't appear. """ print ( "this makes a total of" , total, "assigned points for a level gain of" , level) if total ! = level: print ( "Inconsistent Results. (Level gain not equal to Total Assigned Points.)" ) |
"I want to be a human being, not a human doing."