Oct-14-2020, 04:22 PM
Hi I'm currently learning python in school so am relatively new. I'm working on my own code that generates a random character with its own stats that you can upgrade. I want the player to be able to input something that will repeat lines 39 - 86 is there a way to do this?
import random import time stat1 = random.randint(4, 30) stat2 = random.randint(4, 30) stat3 = random.randint(4, 30) ttl = stat1 + stat2 + stat3 while ttl != 30: stat1 = random.randint(4, 30) stat2 = random.randint(4, 30) stat3 = random.randint(4, 30) ttl = stat1 + stat2 + stat3 if(ttl == 30): print("Strength: " + str(stat1)) print("Agility: " + str(stat2)) print("Heatlh: " + str(stat3)) print("Total Stats: " + str(ttl) + "\n") import random time.sleep(2) hat = random.choice([" ^", " *", " L", " M", " H"]) head = random.choice([" []", " ()", " ||", " {}"]) Body = random.choice(["{}", "|)", "[]", "()"]) arm1 = random.choice(["/", "|", "<", "("]) arm2 = random.choice(["\\", "|", ">", ")"]) Torso = random.choice([" {}", " |)", " []", " ()"]) print(hat) print(head) print(arm1, Body, arm2) print(Torso) print(" ||") print(" LL") time.sleep(2) ansr = input("Improve Stats? (Y/N) ") if(ansr == "Y" or ansr == "y"): time.sleep(1) stchoice = input("Improve which Stat? (Strength, Agility, Health):\n ") if(stchoice == "Strength" or stchoice == "strength"): time.sleep(1) print("Play this mini game to improve your Strength!\n") time.sleep(2) print("Convert this number to a word") print("When entering word don't use capitalization") time.sleep(1) word = (random.choice(["100000.000000", "10000000000.", "10000000000000.0"])) time.sleep(1) print(word) if(word == "100000.000000"): word = ("one hundred thousand") ansrnum = input("Enter the converted number: ") if(ansrnum == "one hundred thousand"): print("Correct!") newst1 = (5 + stat1) print("New strength stat is: " + str(newst1)) time.sleep(1) print("Total Stat is: " + str(ttl + 5)) else: print("Incorrect") if(word == "10000000000."): word = ("ten billion") ansrnum = input("Enter the converted number: ") if(ansrnum == "ten billion"): print("Correct!") newst1 = (5 + stat1) print("New strength stat is: " + str(newst1)) time.sleep(1) print("Total Stat is: " + str(ttl + 5)) else: print("Incorrect") if(word == "10000000000000.0"): word = ("ten trillion") ansrnum = input("Enter the converted number: ") if(ansrnum == "ten trillion"): print("Correct!") newst1 = (5 + stat1) time.sleep(2) print("New strength stat is: " + str(newst1)) time.sleep(1) print("Total Stat is: " + str(ttl + 5)) else: print("Incorrect")