 # Loop(s) not working properly

Hello, I go by Pivot. Recently, I was trying to make a mini Pokemon damage calculator for a friend of mine that would have basic functions using loops and “if/elif/else” statements. The purpose was to make the process much faster and simpler by answering a couple of questions and using those answers to fill in blanks in the damage equation(s). I have tried multiple methods to fix the problem, but to no avail, so as a last resort, I decided to post here. I am only a few months new into using Python, and I currently have version 3.8. Below I will include the code. Any help would be greatly appreciated!

# Stuff needed to import

import math
from fractions import Fraction

# The basic questions

print(“Welcome to the shortcut damage calculator made by Pivot. Check below to begin.”)

print(“What is the base power?”)
power = input()
print(“What is the base attack stat? (It does not matter whether it is physical or special)”)
attack = input()
print(“What is the base defense stat? (It does not matter whether it is physical or special)”)
defense = input()

# Bug-fixing.

power = int(power)
attack = int(attack)
defense = int(defense)

# The default equation for damage calculation

dama = Fraction(Fraction(2 * 100/5) + 2 * power * attack/defense/50) + 2
dama * 1.0

# A-F are replaced by further below code. However, not every letter is replaced, so each one is 1.

A = 1
B = 1
C = 1
D = 1
E = 1
F = 1
damaZ = dama * A * B * C * D * E * F
ABE = 2

# Else statement is an error message meant to tell the user that their answer did not work, and will prompt them to retry.

f = input("Are there other factors? Enter 1 for Yes, 2 for No. ")
def factar():
print(“Your damage is”, damaZ, “% out of the total.”)
quit

``````if f == ABE:
print("Okay. Available commands are STAB, weather, burn, stat change, critical hit.")

else:
print("You must have input a wrong command. Sorry, but you'll have to restart the calculator. :(")
print("If you believe this is a bug, please let me know!")
``````

# and reselecting a different number.

bite = B
print(“Which factor do you wish to add? 1:STAB, 2:Weather, 3:Burn, 4:Stat change.”)
bite = input()

def biet():
for input in bite:
if bite == 1:
A = 1.5
print(“Your damage is”, damaZ, “% out of the total.”)
if bite == 2:
weather = input()
if weather == 1:
B = 0.5
print(“Your damage is”, damaZ, “% out of the total.”)
if weather == 2:
B = 1.5
print(“Your damage is”, damaZ, “% out of the total.”)
if bite == 3:
C = 0.5
print(“Your damage is”, damaZ, “% out of the total.”)
if bite == 4:
print(“Please enter the numerical value of the stat change, from 6 to -6, including 0 as the default.”)
stat = 10
int(stat)
stat = input()

``````        if stat == -6:
D = 2/8
if stat == -5:
D = 2/7
if stat == -4:
D = 2/6
if stat == -3:
D = 2/5
if stat == -2:
D = 2/4
if stat == -1:
D = 2/3
if stat == 0:
D = 1
if stat == 1:
D = 3/2
if stat == 2:
D = 2
if stat == 3:
D = 5/2
if stat == 4:
D = 3
if stat == 5:
D = 7/2
if stat == 6:
D = 4``````

I am not sure whether application development is properly discussed here. Anyhow, your code is a but messed up in the text. I suggest you to create a small git repo to share and discuss your code. Furthermore, please consider using unit tests for your different cases. I highly doubt you found an error in the programming language, it should rather lie in the logic you implemented.

Thank you for the information and advice, I will gladly take this into account and see if I can improve the code.

Hi Lizzy, and welcome!

I’m afraid it is a bit difficult for me to work out what precisely is
wrong with your code. With 100+ lines, it requires a little more
dedication than I currently posses to try to determine the fault given
that I know absolutely nothing about Pokemon.

If you are getting an error message, please copy and paste it (don’t
retype it from memory) and show us. Show us the whole thing, starting
with the line “Traceback”.

It may also help you to help us if you can narrow the problem down
before asking for help by providing a minimal working example. (By
“working”, we mean something we can easily run ourselves to see the
error first hand, not working in the sense of doing the right thing.)
What counts as “minimal” is subjective, but for me, I aim for no more
than 20 lines if at all possible.

This site may help you come up with a minimal working example:

http://sscce.org/

Having said all that, a couple of observations that stood out to me:

damaZ = dama * A * B * C * D * E * F

Since you define all of A…F as exactly 1, that makes damaZ equal to
dama. I’m not sure why you need the multiplication.

``````    print("Your damage is", damaZ, "% out of the total.")
quit
``````

If you are intending to call the `quit` function, you need to use it
with round brackets (parentheses) like this:

``````quit()
``````

Regards,

Steven

1 Like