Reputation: 99
I am currently trying to make a Pokemon Game in Python, however, when you try to catch Pokemon, those legendary Pokemons wont share the same appear rate as normal Pokemons. Therefore I want to import the percentage randomness into the Python, in case you dont understand, this is what I suppose to happen:
Magikrap 10%
Greninja 1%
Lapras 1%
Psyduck 15%
and I want the Python to generate 10 Magikraps if I need it to random generate 100 Pokemons
I am wondering should I import random from Python or what should I do? Thank you
Upvotes: 0
Views: 290
Reputation: 99
from random import randint as r
ran = r(1,100)
if ran == "1":
poke = "Lapras"
elif ran == "2":
poke = ...
so on and so on...
print "You found",poke,"!"
Upvotes: 0
Reputation: 419
You can make a dictionary of Pokemon and their catch rate like: `catch_rate = {"Magikarp": 10}'. You would add more pokemon, of course. Then you could use:
import random
if random.randint(1, 100) < catch_rate[pokemon]:
print "You caught a " + pokemon + "!"
This checks if the random is low enough to be less than the catch rate, and if it is, it is a success. You would need to assign pokemon
a value for this code to work.
Upvotes: 0
Reputation: 633
You can use Random.uniform. Then make a database that has the pokemon and their catch rate. You could even separate this based on area if you wanted to.
Something like:
import random
random.uniform(0,100)
Which in my case was 45.0757219
So you could build a list that looks like this. (Not actual code)
Magikrap 0,10.4
Greninja 10.4,11
Lapras 11,11.3
Psyduck 11.3,15
And then whatever range the number lands in, the player gets the pokemon associated with that range.
Hope it makes sense.
Upvotes: 1