Question:
Im not sure why, but to get certain responses from the console i need to ask the same text input multiple times. How can I fix this?
Repl link:
https://replit.com/@BradyLikes/xpstuff
code snippet
Question:
Im not sure why, but to get certain responses from the console i need to ask the same text input multiple times. How can I fix this?
Repl link:
https://replit.com/@BradyLikes/xpstuff
code snippet
Hey @BradyLikes welcome to the forums!
Your code doesnt seem to be doing anything. I checked the code and it looks fine.
But the program takes input if you run the Repl.
Yeah you need to say the same thing multiple times for it to show anything that’s the issue
Welcome to the forums @BradyLikes!
I think I found your problem. Instead of calling an input from the very start, you’re using an if statement to check if the input is the value. If it’s not, it will move on to the next statement and check the input once again.
xp = 0
level = 0
while True:
xpmax = 100 + level * 20 * (1 + level / 10)
atk = 5 + (2 * level)
defense = 1 + (1 * (level / 2))
hp = 50 + (level * 10 * (1 + level / 10))
if xp >= xpmax:
level += 1
xp = 0
xpmax = 100 + level * 20 * (1 + level /
10)
atk = 5 + (2 * level)
defense = 1 + (1 * (level / 2))
hp = 50 + (level * 10 * (1 + level / 10))
print("LEVEL UP")
print("LEVEL = ", level+1)
if input() == ("add"):
xp += 10
print("XP = ", xp)
elif input() == ("big add"):
xp += 100
print("XP = ", xp)
elif input() == ("check"):
print("XP = ", xp)
print("MAX XP = ", xpmax)
print("LEVEL = ", level+1)
print("ATK = ", atk)
print("DEF = ", defense)
print("HP = ", hp)
You will probably want to change variable names and ask the user to type something rather than just >>
. There is a couple optimizations you should make for your code to look nicer, but this should get the job done.
xp = 0
level = 0
while True:
xpmax = 100 + level * 20 * (1 + level / 10)
atk = 5 + (2 * level)
defense = 1 + (1 * (level / 2))
hp = 50 + (level * 10 * (1 + level / 10))
if xp >= xpmax:
level += 1
xp = 0
xpmax = 100 + level * 20 * (1 + level /
10)
atk = 5 + (2 * level)
defense = 1 + (1 * (level / 2))
hp = 50 + (level * 10 * (1 + level / 10))
print("LEVEL UP")
print("LEVEL = ", level+1)
option = input(">> ")
if option == ("add"):
xp += 10
print("XP = ", xp)
elif option == ("big add"):
xp += 100
print("XP = ", xp)
elif option == ("check"):
print("XP = ", xp)
print("MAX XP = ", xpmax)
print("LEVEL = ", level+1)
print("ATK = ", atk)
print("DEF = ", defense)
print("HP = ", hp)
I hope this fixes your issue.
Thx for the help, now my code is working right
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.