Python Forum
How to re run lines in python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to re run lines in python?
#1
I am making a text based game in python 3.7.2 but if users type somtheing wrong I want it to re run a line and let them try again but it doesn't work.I have been cracking my head and I can't figure it out.Here is the script so far:

print("Hello I hpoe that everything is working.If you see this everything probably works.Type MENU to see the options.")
options = input()
if options == 'MENU' or options == 'Menu' or options == 'menu':
    print("START                        NOTE-TYPE TO INTERACT")
game_start = input()
if game_start == 'START' or 'START' or 'Start':
    print("Ok Let's begin with the game.")
print("LOADING STARTING IN 7 SECONDS")   
import time
time.sleep(7)
for k in range(1000):
    print(k)
print('LOADED')
print("You are on a field and you see a mansion in the distance.You can't remember anything.There is somtheing shiny on the floor.")
Reply
#2
You can use a while loop similar to code below from the python docs tutorial here
def ask_ok(prompt, retries=4, reminder='Please try again!'):
    while True:
        ok = input(prompt)
        if ok in ('y', 'ye', 'yes'):
            return True
        if ok in ('n', 'no', 'nop', 'nope'):
            return False
        retries = retries - 1
        if retries < 0:
            raise ValueError('invalid user response')
        print(reminder)
Reply
#3
I have loked at the wiki but I still do not not what to do help... Cry Cry Cry
Reply
#4
We need something more than "I don't know what to do." Yoriz posted a good example of code to repeat a question multiple times until you get a valid yes or no answer. What do you not understand about that? How does it not fix your problem.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
Sorry,
I don't know hot implement that into my code
Reply
#6
Sorry I got it now Smile Smile Smile
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  What are these python lines for? What are tey doing? Led_Zeppelin 7 1,561 Feb-13-2023, 03:08 PM
Last Post: deanhystad
  python seems to be skipping lines of code alansandbucket 1 4,088 Jun-22-2021, 01:18 AM
Last Post: Larz60+
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 5,706 Aug-10-2020, 11:01 PM
Last Post: medatib531
  Arrange lines in python pythonlover 11 7,161 Sep-15-2017, 11:34 PM
Last Post: pythonlover
  parallel(offset) lines using python johnfriend 1 4,234 May-05-2017, 06:10 AM
Last Post: buran

Forum Jump:

User Panel Messages

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