Python Forum
Repeating lines of code by an input
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Repeating lines of code by an input
#1
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")
Reply


Messages In This Thread
Repeating lines of code by an input - by Josh_Albanos - Oct-14-2020, 04:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is 2/3 not just .666 repeating? DocFro 4 716 Dec-12-2023, 09:09 AM
Last Post: buran
Question in this code, I input Key_word, it can not find although all data was exact Help me! duchien04x4 3 1,058 Aug-31-2023, 05:36 PM
Last Post: deanhystad
  repeating a user_input astral_travel 17 2,316 Oct-26-2022, 04:15 PM
Last Post: astral_travel
  Code won't break While loop or go back to the input? MrKnd94 2 967 Oct-26-2022, 10:10 AM
Last Post: Larz60+
  Regular Expression search to comment lines of code Gman2233 5 1,705 Sep-08-2022, 06:57 AM
Last Post: ndc85430
  Help Switching between keyboard/Mic input in my code Extra 1 1,102 Aug-28-2022, 10:16 PM
Last Post: deanhystad
  if else repeating Frankduc 12 2,525 Jul-14-2022, 12:40 PM
Last Post: Frankduc
  matching a repeating string Skaperen 2 1,259 Jun-23-2022, 10:34 PM
Last Post: Skaperen
  I want to simplify this python code into fewer lines, it's about string mandaxyz 5 2,140 Jan-15-2022, 01:28 PM
Last Post: mandaxyz
  python seems to be skipping lines of code alansandbucket 1 4,174 Jun-22-2021, 01:18 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020