Python Forum
Unknown Error with Random Stat Assigner
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unknown Error with Random Stat Assigner
#1
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.

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 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?
"I want to be a human being, not a human doing."
Reply


Messages In This Thread
Unknown Error with Random Stat Assigner - by FC8 - Dec-01-2021, 05:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error UserWarning: Unknown option ssl_ca_certs warnings.warn(str(exc)) Vijayaraj 0 837 Jul-11-2023, 06:01 AM
Last Post: Vijayaraj
  Failing to get Stat for a Directory tester_V 11 3,872 Jul-20-2021, 10:59 PM
Last Post: Larz60+
  Unknown error occurred: Port not found NewBeie 0 1,516 Aug-27-2020, 08:50 PM
Last Post: NewBeie
  Help!Unknown ERROR bwdu 1 2,173 Apr-20-2020, 02:09 PM
Last Post: deanhystad
  Unknown error TheIDarKIKnight 0 1,576 Apr-19-2020, 05:27 PM
Last Post: TheIDarKIKnight
  Unknown error in pygame :( TheDovah77 1 2,966 Apr-14-2019, 10:22 PM
Last Post: metulburr
  Unknown syntax error (Im new to this) reasonablelevel 2 2,946 Jul-25-2018, 11:59 AM
Last Post: reasonablelevel
  weird error in random sentence generator bobger 9 5,960 Nov-29-2017, 07:34 PM
Last Post: bobger
  Unknown Syntax Error AlwaysNew 6 5,481 Sep-09-2017, 01:57 AM
Last Post: AlwaysNew

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020