Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to fix the error?
#1
My current code:
import time
import random
import os

ValidBootFiles = ["XC_DOS", "shell"]

for x in range(100):
    bootfrom = input("boot from:")
    if bootfrom == "XC_DOS":
        print("trying to boot from XC_DOS...")
        for x in range(99):
             print("")
    print("                                                                                      XC DOS")

    for x in range(25):
        print("")
    print("starting up...")
    for x in range(20):
        print("=", end='', flush=True)
        time.sleep(0.1)
        print("=", end='', flush=True)
        time.sleep(0.2)
        print("=", end='', flush=True)
        time.sleep(0.4)
        print("=", end='', flush=True)
        time.sleep(0.2)
        print("=", end='', flush=True)
        time.sleep(0.3)
        print("=", end='', flush=True)
        time.sleep(0.1)
        print("=", end='', flush=True)
        time.sleep(0.2)
        print("=", end='', flush=True)
        time.sleep(0.1)
        print("=", end='', flush=True)

    print("=")
    time.sleep(1)
    end = time.sleep(3)

    time.sleep(3)
    for x in range(99):
        print("")
    while True:
        user = input('Your username goes here: ')
        if user == 'Adrian':
            for x in range(90):
                print("")
            passwd = input('Your password goes here: ')
            if passwd == 'password1':
                print("")
                for x in range(90):
                    print("")
                print(f'{user}, you are now logged in. This message will be displayed for 5 seconds.')
                time.sleep(5)
                print("mini command line v1.0.0")
                print("type help for a list of commands.")
                for x in range(99):
                    print("")

                print("XC DOS shell")
                print("type help for a list of commands.")
                print("")


                def commandline():
                    commandline = input("command>")
                    return commandline


                commands = ["help", "dir", "exit", "vson", "N.E.P.T.E.R"]

                commandline_string = ""
                while commandline_string != "exit":
                    commandline_string = commandline()

                    if not commandline_string in commands and commandline_string != "":
                        print(
                            f"Unable to run {commandline_string}. Please check that the command exists and that you have permission to use it.")

                    if commandline_string == "help":
                        print("These are the valid commands")
                        for command in commands:
                            print(command)

                    elif commandline_string == "dir":
                        files = os.listdir("/")
                        for file in files:
                            print(file)

                    elif commandline_string == "vson":
                        print("XC DOS 1.2.0")
                        print("")

                    elif commandline_string == "N.E.P.T.E.R":
                        for x in range(10):
                            import random

                            drinks = ["F3#$%S4", "f#$f34#", "D50w9#f", "F#$f34F", "#$i5iS", "F3Fwjis3##w",
                                      "f##f#fwg#345f^d6", "e%d3h4Hw4", "cT46$^s56_3", "3F#$f34F_E$_"]

                            drink1 = random.choice(drinks)
                            drink2 = random.choice(drinks)
                            drink3 = random.choice(drinks)
                            print(drink1)
                            print(drink2)
                            print(drink3)
                            if drink1 == drink2 and drink2 == drink3:
                                print("Jackpot! And you win $3785934758394758937485934857489345739!")
                                redo = input("wanna do another round? [Y/N]")
                                if redo == "y":
                                    import random

                                    drinks = ["f#%s45", "f3f39$", "f4jf$#", "f#%3f4", "3FS4d#$", "3F#5F%d5"]

                                    drink1 = random.choice(drinks)
                                    drink2 = random.choice(drinks)
                                    drink3 = random.choice(drinks)
                                    print(drink1)
                                    print(drink2)
                                    print(drink3)



                    elif commandline_string == "exit":
                        print("A critical error occoured.")
                        print("error code: 000013FS42x00")
                        print("Returning to MacOS to avoid further damage...")
                        print("done.")
                        print(
                            "Please input Boot path to run this or something else. The path may look like this: /Users/Virsatech/PycharmProjects/maze_script/venv/bin/python /Users/Virsatech/PycharmProjects/maze_script/XC_DOS.py")
                break
            else:
                print('Wrong password. Please try again.')
                continue
        else:
            print('Wrong username. Please try again.')
            continue

    elif bootfrom == "shell":
        print("testing shell")

    if not bootfrom in ValidBootFiles:
        print("invalid")
When I run it:
Error:
File "/Users/*********/PycharmProjects/maze_script/BootX.py", line 140 elif bootfrom == "shell": ^ SyntaxError: invalid syntax
Reply
#2
The indentation of line 140 does not pair up with an earlier if, but instead with the while on line 44.

It is possible for a while loop to have an else clause, but not an elif, so this is an error. Which if were you expecting it to based off?

It can be difficult to keep track of such a long block of code with so many loops. I think it would be better if you could break it into parts with different functions rather than one long block. For instance make a function to ask for username/password and validation and return the credentials. Then that section doesn't have to wrap later portions.
Reply
#3
(Apr-04-2021, 07:42 PM)bowlofred Wrote: The indentation of line 140 does not pair up with an earlier if, but instead with the while on line 44.

It is possible for a while loop to have an else clause, but not an elif, so this is an error. Which if were you expecting it to based off?

It can be difficult to keep track of such a long block of code with so many loops. I think it would be better if you could break it into parts with different functions rather than one long block. For instance make a function to ask for username/password and validation and return the credentials. Then that section doesn't have to wrap later portions.

Thanks.
Reply


Forum Jump:

User Panel Messages

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