Repeat code after the string has ended


#1

Please leave the following link in the post so we can find the unit module, else replace it with a link to the exact lesson:

Strings and Console Output

Take a look at the code below:


     #Ninja

#Cases = 26,28,30
"""
_______________
|             |
|Feb  2018    |
|             |
| --------    |
|             |
|             |
|             |
|             |
---------------
"""
from random import randint
repeat = True
import time
import sys
import multiprocessing
import replit
import random
from threading import Timer
from __builtin__ import raw_input
from termcolor import colored, cprint
#for x in range(0, 3):
 #   print "We're on time %d" % (x)

def print_slow(str):
    for letter in str:
        sys.stdout.write(letter)
        sys.stdout.flush()
        time.sleep(0.1)
        

def character_1(str):
    for letter in str:
      print(".")
staminstart = int(100)
cprint("Ninja", attrs=['blink','bold']) 
print("")
time.sleep(1)
 
print("")
print("")
print("1. Start\n2. Rules\n3. Info")
beginning = raw_input()
if beginning == "2":
  print("The rules are simple.\nYou get good and follow the roleplay and keep improving it until this game ends. That's all..")
elif beginning == "3":
  print("This game is just for fun")
  
  #
#
  #
elif beginning == "1":
  print("Create your character!")
  print("What hair color would you like your character to have?")
  haircolor = raw_input()
  print("")
  print("What custom nickname do you want for your character?")
  print("")
  nick = raw_input()
  print("")
  print("Welcome, %s !!") % (nick)
  time.sleep(1)
  print("A rogue ninja appears fight or avoid? F/A")
  print("")
  print("Type in 'F' to fight, or type in 'A' to avoid.")
  fa1 = raw_input()
  if fa1 == "A":
   print("You run away for your life")
   time.sleep(2)
   print("RUNNING BACK TO VILLAGE")
   time.sleep(2)
   print("RUNNING BACK TO VILLAGE")
   time.sleep(2)
   print("RUNNING BACK TO VILLAGE")
   time.sleep(3)
   print("You are back to your village and are very tired. Stamina = 20/100")
   time.sleep(1)
   print("Drinking juice to regain stamina")
   time.sleep(2)
   print("40%")
   time.sleep(2)
   print("80%")
   time.sleep(1)
   print("You now have 100% stamina")
   time.sleep(1.2)
   print("Would you like to go to sleep or go hunting?")
   sleephunt = raw_input()
   if sleephunt == "sleep":
    print("You have chosen to sleep..")
    print("")
    time.sleep(3)
    print("You wake up the next morning dizzy. You start your work, but suddenly fall. You went into a coma for 2 months because of eating a poisonous plant.")
    print("")
    time.sleep(5)
    print("2 MONTHS LATER","white")
    print("")
    time.sleep(4)
    print("You can barely open your eyes. You can barely move. You get up, and get out of the house.")
    print("")
    time.sleep(3)
    print("")
    time.sleep(2)
    print_slow ("Ninja")
    print("")
    print("")
    time.sleep(3)
    print("2 Years later...")
    print ("")
    time.sleep(4)
    print("The village has developed. There are a lot of people now. But out of all of them, they chose you , %s") % (nick)
    print("")
    time.sleep(5)
    print("You sit in your huge cottage. A villager comes in. He says that there are people that came here and are asking to see the leader..\nDo you accept?")
    accept = raw_input()
    if accept == "yes":
      time.sleep(1)
      print("You have accepted to talk to them")
      print("They come in your cabin, but then they throw shurikens at you")
      time.sleep(2)
      print("You dodge and get your katana")
      time.sleep(3)
      print("SLASH","cyan")
      time.sleep(2)
      print("You injured one.")
      print("They beg for mercy, do you spare them?")
      spare = raw_input()
      if spare == "no":
        print("You injure the other one and throw them in jail")
        print ("You start interrogating them.")
        time.sleep(2)
        print("Which question do you ask?")
        time.sleep(1)
        print("1. Who are you?")
        time.sleep(0.50)
        print("2. Why are you here?")
        time.sleep(0.50)
        print("3. Who sent you?")
      else:
        print("You spare them and interrogate them")
        print("They say they are here by someone named...")
        time.sleep(2)
        print("BOOM. The person you were interrogating fell.")
    else:
      print("You have denied to talk to them")
      print("The day passes. You are going to sleep. SLASH")
      print("Someone is here.")
   else:
     print("You take a katana with you.")
     time.sleep(1)
     print("There is a bear, and a cow. Which one do you kill?")
     time.sleep(0.50)
     print("1. Bear\n2. Cow")
     kill = raw_input()
     if kill == "1":
       print_slow("It takes you by surprise...")
       time.sleep(1)
       print("You")
       time.sleep(0.50)
       print_slow("Die...", attrs =['blink'])
  else:
   print("Which move do take??")
   time.sleep(0.25)
   print("1. Neptune Thrust\n2. Sword Slash\n3. Sneak behind")
   move1 = raw_input()
   if move1 == "1":
     print("You use the Trident")
     time.sleep(0.2)
     print("")
     print_slow("...")
     print("\n♆")
     print_slow("...")
     critical = random.randint(1,100)
     if critical <= 25:
       print("CRITICAL HIT.. Enemy Health -- 40/100")
     else:
       print("SLASH... Enemy Health -- 70/100")
   elif move1 == "2":
     print("You use your long sword")
     time.sleep(0.2)
     print("")
     print_slow("...")
     print("\n🗡️")
     print_slow("...")
     critical = random.randint(1,100)
     if critical <= 25:
       print("CRITICAL HIT... Enemy Health -- 55/100")
     else:
       print("HIT... Enemy Health -- 65/100")
   elif move1 == "3":
     print("You sneak behind the enemy")
     time.sleep(0.2)
     print("")
     print_slow(".........Sneaking........\n........Sneaking.........\n......Sneaking........\n")
     sneak = random.randint(1,100)
     if sneak <= 60:
      print_slow("UNDETECTED")
      print("")
      time.sleep(0.50)
      critical = random.randint(1,100)
      if critical <= 25:
       print("CRITICAL HIT... Enemy Health -- 60/100")
      else:
       print("KICK... Enemy Health -- 75/100")
     else:
       print_slow("DETECTED!!!")
       time.sleep(0.50)
       print("The enemy catches on to you..")
       print("...")
       print("You got hit!!! Health -- 45/100")
       print("")
       time.sleep(0.5)
       print("Your turn now...\nWhat move do you take?")
       print("")
       print_slow("1. Dagger Rain\n2. Lightning Strike\n3. Quick throw ")
       move2 = raw_input()
       if move2 == "1":
         print("Throwing volley of daggers on the enemy...")
         time.sleep("0.5")
         print("🗡️🗡️🗡️🗡️\n🗡️🗡️🗡️\n🗡️️")
       elif move2 =="2":
         print("Lightning Strike (40%) Hit")
         hit = random.randint(1,100)
         if hit <= 40:
           print("STARTING TO HIT....")
           print("")
           time.sleep(0.2)
           print("BOOOM... Enemy Health -- 45/100")
         else:
           print("Lightning Strike Failed...")
           
           

Look at the beginning lines. For example, I ask the user if they want to start the game, look at the rules, or just learn what the game is about. For example if they input 2, that just gives them the rules. But when they do input that, the game just ends. I want to make it so that when they type in 2 or 3 to view the rules , etc , it gives them the option of starting the game after they had read the rules.
Sorry if this is confusing.


#2

you could simply make an infinity while loop (while True) then allow the user to enter 4 to break the loop and exit the program


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.