Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

Python MY CODE WORKS BUT SUDDENLY IT DOESN"T, I ADDED SOME PRINT FOR DEBUGGING BUT STILL CANT< PLZ HELP ME

huionoob

New Coder
#AttackPower : input the raw power of the LAST pokemon attack, not compatible with attacks contains special effects #AttackCost : 1.5 for specific energy, 1 for colorless energy PokemononeHP = 1000 Prizeone = 1 Resistanceone = 0 OneFinalPower = 0 OneAttackPower = 20 AttackCostOne = 2 OneEvolution = 0 PokemontwoHP = 90 Prizetwo = 1 Resistancetwo = 30 TwoFinalPower = 0 TwoAttackPower = 60 AttackCostTwo = 2.5 TwoEvolution = 2 OneFinalPowerstepone = 0 OneFinalPowersteptwo = 0 OneFinalPowerstepthree = 0 OneFinalPowerstepfour = 0 TheVeryFinalResultOfPokemonOne = 0 TwoFinalPowerstepone = 0 TwoFinalPowersteptwo = 0 TwoFinalPowerstepthree = 0 TwoFinalPowerstepfour = 0 TheVeryFinalResultOfPokemonTwo = 0 def prizecardcalculation(): Powertakenbyeachprizecard = (PokemononeHP+PokemontwoHP)/2 OneFinalPowerstepone = OneFinalPower - (Powertakenbyeachprizecard * Prizeone) TwoFinalPowerstepone = TwoFinalPower - (Powertakenbyeachprizecard * Prizetwo) print("Pokemon one gets minus " + str(Powertakenbyeachprizecard * Prizeone) + " power.") print("Pokemon two gets minus " + str(Powertakenbyeachprizecard * Prizetwo) + " power.") def resistancefavour(): if Resistanceone == 0: print("Pokemon one gets no resistance favour.") else: print("Resistance favour added for pokemon one.") OneFinalPowersteptwo = OneFinalPowerstepone + Resistanceone if Resistancetwo == 0: print("Pokemon two gets no resistance favour.") else: print("Resistance favour added for pokemon two.") TwoFinalPowersteptwo = TwoFinalPowerstepone + Resistancetwo print(TwoFinalPowersteptwo) def stageweakness(): global OneFinalPowerstepthree, TwoFinalPowerstepthree stageweaknessbase = 0 if PokemononeHP > PokemontwoHP: stageweaknessbase = PokemononeHP - PokemontwoHP stageweaknessbase * OneEvolution OneFinalPowerstepthree = OneFinalPowersteptwo - stageweaknessbase TwoFinalPowerstepthree = TwoFinalPowersteptwo if PokemontwoHP > PokemononeHP: stageweaknessbase = PokemontwoHP - PokemononeHP stageweaknessbase * OneEvolution TwoFinalPowerstepthree = TwoFinalPowersteptwo - stageweaknessbase OneFinalPowerstepthree = TwoFinalPowerstepthree print(OneFinalPowerstepthree) print(TwoFinalPowerstepthree) def functionattackefficency(): Oneefficency = 0 Twoefficency = 0 Oneefficency = OneAttackPower / AttackCostOne Twoefficency = TwoAttackPower / AttackCostTwo print("Attack efficency for pokemon one = " + str(Oneefficency)) print("Attack efficency for pokemon two = " + str(Twoefficency)) OneFinalPowerstepfour = OneFinalPowerstepthree + Oneefficency TwoFinalPowerstepfour = TwoFinalPowerstepthree + Twoefficency print(OneFinalPowerstepfour) def hitpointsdifference(): diffenrence = 0 if PokemononeHP > PokemontwoHP: diffenrence = PokemononeHP - PokemontwoHP print("Hit points diffenrence is " + str(diffenrence) + " more for Pokemon one") TheVeryFinalResultOfPokemonOne = OneFinalPowerstepfour + diffenrence print(TheVeryFinalResultOfPokemonOne) if PokemontwoHP > PokemononeHP: diffenrence = PokemontwoHP - PokemononeHP print("Hit points diffenrence is " + str(diffenrence) + " more for Pokemon two") TheVeryFinalResultOfPokemonTwo = TwoFinalPowerstepfour + diffenrence def finalpowercalculation(): print(TheVeryFinalResultOfPokemonOne) if TheVeryFinalResultOfPokemonOne > TheVeryFinalResultOfPokemonTwo: print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") print("POKEMON ONE IS THE WINNER WITH " + str(TheVeryFinalResultOfPokemonOne) + " CALCULATION POINTS!!!") print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") if TheVeryFinalResultOfPokemonTwo > TheVeryFinalResultOfPokemonOne: print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") print("POKEMON TWO IS THE WINNER WITH " + str(TheVeryFinalResultOfPokemonTwo) + " CALCULATION POINTS!!!") print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") else: print("A TIE OF POWER!!!") print(TheVeryFinalResultOfPokemonOne) print("POKEMON ONE STANDING STILL WITH " + str(TheVeryFinalResultOfPokemonOne) + " POINTS") print("POKEMON TWO HOLDING THE MIGHTY WITH " + str(TheVeryFinalResultOfPokemonTwo) + " POINTS") def runfunctions(): prizecardcalculation() resistancefavour() stageweakness() functionattackefficency() hitpointsdifference() finalpowercalculation() #Final run: runfunctions()
 
"Suddenly it doesn't" ? What have you changed ? A friendly advice: don't just dump your code, scream for help in all caps, and expect someone to sort out your program...

BTW Python code posted like this is totally useless. All the indentation is gone, making it impossible to see or even recreate the program flow (if any).
 
So what what does this code do? After fixing the indentation this is the ouput.

Code:
Pokemon one gets minus 545.0 power.
Pokemon two gets minus 545.0 power.
Pokemon one gets no resistance favour.
Resistance favour added for pokemon two.
30
Attack efficency for pokemon one = 10.0
Attack efficency for pokemon two = 24.0
-900.0
Hit points diffenrence is 910 more for Pokemon one
910
0
A TIE OF POWER!!!
0
POKEMON ONE STANDING STILL WITH 0 POINTS
POKEMON TWO HOLDING THE MIGHTY WITH 0 POINTS
 
You may want to look into python classes. It would save a lot of redundant typing.
Pokemon class example.

Python:
import random as rnd
class Pokemon:
    def __init__(self):
        self.attributes = {
            'hp': 1000,
            'resistance': rnd.randint(1, 20),
            'attack': rnd.randint(1, 20),
            'attack_cost': round(rnd.uniform(1, 3), 2),
            'prize': 1,
            'evolution': 0
        }


pokemon1 = Pokemon()
pokemon2 = Pokemon()

print('pokemon1')
for key, value in pokemon1.attributes.items():
    print(f'{key}: {value}')
print()

print('pokemon2')
for key, value in pokemon2.attributes.items():
    print(f'{key}: {value}')

Output
Code:
pokemon1
hp: 1000
resistance: 9
attack: 5
attack_cost: 1.54
prize: 1
evolution: 0

pokemon2
hp: 1000
resistance: 7
attack: 19
attack_cost: 2.29
prize: 1
evolution: 0
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom