Problemexpand_less
A good superhero gives hope to people in trouble. Let's create a generator for random superhero ideas - the results might be silly, but maybe it will give you the inspiration you need to create a great hero!
Default Random Choicesexpand_less
Name
Even chance of starting with "Captain", "Doctor", "Star", "Power", "The Human"
Ends with a word determined by the power theme
Power Theme
2 in 8 chance: "fire" (+3 power)
2 in 8 chance: "wind" (+3 power)
2 in 8 chance: "water" (+3 power)
1 in 8 chance: "ghosts" (+4 power)
1 in 8 chance: "light" (+2 power)
Power Description
1 in 10 chance: can "summon" the theme (+4 power)
3 in 10 chance: can "turn into" the theme (+3 power)
3 in 10 chance: can "shoot beams of" the theme (+2 power)
3 in 10 chance: can "talk to" the theme (+1 power)
Extra Power
There is a 1 in 2 chance the hero has an extra power
If they do, there is an even chance of these options:
"is invincible" (+4 power)
"can stop time" (+3 power)
"is an expert hacker" (+3 power)
"can fly" (+2 power)
Inputexpand_less
None
Outputexpand_less
Superhero name
Hero abilities
Rating of the superhero's power
Requirements expand_less
Use multiple random choices to generate a superpower and hero name
Use weighted choice to make some power options rarer and more powerful than others
Track the hero's power rating depending on the choices of power
"""
Built-In Libraries
Coding Exercise: Randomness
Super Random
"""
#### ---- SETUP ---- ####
import random
## -- Libraries -- ##
name=" "
theme=" "
## -- Variables -- ##
power=0
hero_name=random.randint(2,8)
#### ---- RANDOMIZATION ---- ####
## -- First part of name -- ##
rand_name=random.randint(1,5)
if rand_name==1:
name="Captain "
elif rand_name==2:
name=="Doctor "
elif rand_name==3:
name= "Star "
elif rand_name==4:
name=="Power"
elif rand_name==5:
name=="The Human "
## -- Theme choice -- ##
theme_choice=random.randint(1,8)
## -- Power description -- ##
power+=4
## -- Extra power -- ##
#### ---- RESULTS ---- ####
print("superhero " + name + last)
print(name +" "+ last+" " + desc)