Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to make it so that when the user chooses a number, the user's character will train for x amount of hours. However, when I choose a number other than 1, the code will still print the code for 1 hour.


import random
import time

bot = random.choice(["1","2","3","4","5"])
ATK = 1
DEF = 1
STR = 1
HP = 1
training = True
alive = True
combat = True
rest = "Rest" and "rest"
trainc = "Train" and "train"
stats =["ATK = " +str(ATK), "DEF= " + str(DEF), "STR = " + str(STR), "HP = " + str(HP)]

name = input("What is your name, fighter?: ")

print("Welcome to the Bare Knuckle Arena," + name + ".\n" "These are your current stats:" +  str(stats) + "\nFight and train to increase them.\nSee you in the morning.\n")
time.sleep(4)


print("Good morning fighter! It is time to train!")
train = input("What do you want to train today? (ATK,DEF,STR,HP):")
train_time = int(input("How long do you want to train for?(hrs): "))


if train =="ATK" or train == "atk" and train_time == "1":
    print("You duel for 1 hour...")
    time.sleep(3)
    ATK = ATK + 1
    print("ATK has increased to: " + str(ATK))
            
elif train =="ATK" or train == "atk" and train_time == "2":
        print("You duel for 2 hours...")
        time.sleep(3)
        ATK = ATK + 2
        print("ATK has increased to: " + str(ATK))
elif train =="ATK" or train == "atk" and train_time == "3":
        print("You duel for 3 hours...")
        time.sleep(3)
        ATK = ATK + 3
        print("ATK has increased to: " + str(ATK))
            
elif train =="ATK" or train == "atk" and train_time == "4":
        print("You duel for 4 hours...")
        time.sleep(3)
        ATK = ATK + 4
        print("ATK has increased to: " + str(ATK))

if train =="DEF" or train == "def" and train_time == "1":
            print("You spar for 1 hour...")
            time.sleep(3)
            DEF = DEF + 1
            print("DEF has increased to: " + str(DEF))
elif train =="DEF" or train == "def" and train_time == "2":
            print("You spar for 2 hours...")
            time.sleep(3)
            DEF = DEF + 2            
            print("DEF has increased to: " + str(DEF))

elif train =="DEF" or train == "def" and train_time == "3":
            print("You spar for 3 hours...")
            time.sleep(3)
            DEF = DEF + 3
            print("DEF has increased to: " + str(DEF))

elif train =="DEF" or train == "def" and train_time == "4":
            print("You spar for 4 hours...")
            time.sleep(3)
            DEF = DEF + 4
            print("DEF has increased to: " + str(DEF))

if train =="STR" or train == "str" and train_time == "1":
            print("You workout for 1 hour...")
            time.sleep(3)
            STR = STR + 1
            print("STR has increased to: " + str(STR))
elif train =="STR" or train == "str" and train_time == "2":
            print("You workout for 2 hours...")
            time.sleep(3)
            STR = STR + 2            
            print("STR has increased to: " + str(STR))

elif train =="STR" or train == "str" and train_time == "3":
            print("You workout for 3 hours...")
            time.sleep(3)
            STR = STR + 3
            print("STR has increased to: " + str(STR))

elif train =="STR" or train == "str" and train_time == "4":
            print("You workout for 4 hours...")
            time.sleep(3)
            STR = STR + 4
            print("STR has increased to: " + str(STR))
            

if train =="HP" or train == "hp" and train_time == "1":
            print("You run for 1 hour...")
            time.sleep(3)
            HP = HP + 1
            print("HP has increased to: " + str(HP))
elif train =="HP" or train == "hp" and train_time == "2":
            print("You run for 2 hours...")
            time.sleep(3)
            HP = HP + 2            
            print("HP has increased to: " + str(HP))

elif train =="HP" or train == "hp" and train_time == "3":
            print("You run for 3 hours...")
            time.sleep(3)
            HP = HP + 3
            print("HP has increased to: " + str(HP))

elif train =="HP" or train == "hp" and train_time == "4":
            print("You run for 4 hours...")
            time.sleep(3)
            HP = HP + 4
            print("HP has increased to: " + str(HP))
else:
    while train != "ATK" and train != "DEF" and train != "HP" and train != "STR":
        print("Please choose a valid option.")
        train = input("What do you want to train today? (ATK,DEF,STR,HP):")

if train_time > 4:
    print("You will be over training! Choose less than 4 hours.")
    train = input("What do you want to train today? (ATK,DEF,STR,HP):")
    train_time = input("How long do you want to train for?: ")

if train_time < 4:
    rt = input("Would you like to rest or keep training?(Rest/Train):")
    if rt == "Rest" or "rest":
        print("Good job training today.Tommorow you have your first fight. Good luck.")
        print("")
        print("You rest...")
        time.sleep(5)
    elif rt == "Train" and "train":
        train = input("What do you want to train? (ATK,DEF,STR,HP):")
        train_time = int(input("How long do you want to train for?: "))


What I have tried:

I have tried rearranging the conditionals and using or instead of and, and I don't know where to go from there
Posted
Updated 18-Mar-22 12:03pm
Comments
Richard MacCutchan 19-Mar-22 5:36am    
elif rt == "Train" and "train":

That expression could never work in any language; rt cannot be equal to both values at the same time.

1 solution

Quote:
Why don't the elif statements work?

Because some of your elif are not Python.
Look at your code you have 3 ways to ask for the same thing, but 2 of them is not Python.
Python
if   train =="HP" or train == "hp" and train_time == "1":

elif train =="HP" or train == "hp" and train_time == "2":

elif train =="HP" or train == "hp" and train_time == "3":

elif train =="HP" or train == "hp" and train_time == "4": # Python

    if   rt == "Rest" or "rest": # Not Python

    elif rt == "Train" and "train": # Not Python
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900