Python Forum
Help Me With This Issue Please - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Help Me With This Issue Please (/thread-25556.html)



Help Me With This Issue Please - 00banyaszo00 - Apr-03-2020

So I have been having this issue where if I paste a code into a new file it works but if I leave it where it's supposed to be it says 'syntax error' or is I fix that it gives me an 'IndentationError: expected an indented block'. What I am trying to make is let's call it a password system where you can only type in four things and if you fail it will say 'invalid command'. Oh yeah and by the way I want to loop this around 4 times and on the fifth try I want to do something else but if you take any less than 5 tries the tat thing won't happen. Please explain it in a starter friendly manner. Thank you! Oh yes and just to repeat I am having trouble with the else in this code.

here's the code that I want to repeat four times:

else:

            print (" ")
            print ("DUDE YOU CAN'T YOU SPELL 'Calcululator' OR WHAT!? Huh go on try another time.")
            print (" ")
            Command_calculator = input("Enter Cal-cu-la-tor OK? easy: ")
            if Command_calculator == "calculator" or Command_calculator == "Calculator" or Command_calculator == "calc" or Command_calculator == "Calc" or Command_calculator == "Cal-cu-la-tor":
                else:
                    print (" ")
                    ("NOPE!!! Thats it! I am BANNING you from my game!")
                    time.sleep(999999)
And here's the command that I want to put after that (if all four fails):

print (" ")
print ("DUDE YOU CAN'T YOU SPELL 'Calcululator' OR WHAT!? Huh go on try another time.")
print (" ")
Command_calculator = input("Enter Cal-cu-la-tor OK? easy: ")
if Command_calculator == "calculator" or Command_calculator == "Calculator" or Command_calculator == "calc" or Command_calculator == "Calc" or Command_calculator == "Cal-cu-la-tor"
              else:
                   print (" ")
                   ("NOPE!!! That's it! I am BANNING you from my game!")
                   time.sleep(999999)
the last else is the else that I am having trouble with.


Help Me With This Issue Please (FIXED) - 00banyaszo00 - Apr-03-2020

So I have been having this issue where if I paste a code into a new file it works but if I leave it where it's supposed to be it says 'syntax error' or is I fix that it gives me an 'IndentationError: expected an indented block'. What I am trying to make is let's call it a password system where you can only type in four things and if you fail it will say 'invalid command'. Oh yeah and by the way I want to loop this around 4 times and on the fifth try I want to do something else but if you take any less than 5 tries the tat thing won't happen. Please explain it in a starter friendly manner. Thank you! Oh yes and just to repeat I am having trouble with the else in this code.

here's the code that I want to repeat four times:

Command_calculator = input("Enter \"Calculator\" here: ")
if Command_calculator == "calculator" or Command_calculator == "Calculator" or Command_calculator == "calc" or Command_calculator == "Calc":
    print (" \n \n ")
else:
    print (" ")
    print ("Invalid command try again.")
    print (" ")
And here's the command that I want to put after that (if all four fails):

print (" ")
print ("DUDE YOU CAN'T YOU SPELL 'Calcululator' OR WHAT!? Huh go on try another time.")
print (" ")
Command_calculator = input("Enter Cal-cu-la-tor OK? easy: ")
if Command_calculator == "calculator" or Command_calculator == "Calculator" or Command_calculator == "calc" or Command_calculator == "Calc" or Command_calculator == "Cal-cu-la-tor"
              else:
                   print (" ")
                   ("NOPE!!! That's it! I am BANNING you from my game!")
                   time.sleep(999999)
the last else is the else that I am having trouble with. (Sorry for the last one)


RE: Help Me With This Issue Please (FIXED) - GalaxyCoyote - Apr-03-2020

What is going on is that your else is way to indented.
Here is what the second code block should look like:
print (" ")
print ("DUDE YOU CAN'T YOU SPELL 'Calcululator' OR WHAT!? Huh go on try another time.")
print (" ")
Command_calculator = input("Enter Cal-cu-la-tor OK? easy: ")
if Command_calculator == "calculator" or Command_calculator == "Calculator" or Command_calculator == "calc" or Command_calculator == "Calc" or Command_calculator == "Cal-cu-la-tor":
    pass
else:
    print (" ")
    ("NOPE!!! That's it! I am BANNING you from my game!")
    time.sleep(999999)
Not only that, but you have an unused if statement, I have fixed that. In python, if you have something that is indented but you don't use it, it will spit out an error. Your error was because you didn't put a ":" at the end of the first if statement in the second block.

Basically, just put whatever code you want to run where "pass" is.

Hope this helps!

EDIT: it didn't recognise the code block tag, I have fixed my answer so it is more readable


RE: Help Me With This Issue Please - ndc85430 - Apr-03-2020

The if statement on line 7 is empty and the corresponding else should be at the same level of indentation. Regarding the first point, are you actually wanting to only do something if the condition on line 7 isn't satisfied? If so, why are you not writing it with a negation (i.e. if not ...:)?


RE: Help Me With This Issue Please - perfringo - Apr-03-2020

Instead of this monster-line:

if Command_calculator == "calculator" or Command_calculator == "Calculator" or Command_calculator == "calc" or Command_calculator == "Calc" or Command_calculator == "Cal-cu-la-tor"
One can write more readable:

if Command_calculator.lower() in ['calculator', 'calc', 'cal-cu-la-tor']: