Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Text Game Not Working [SOLVED]
-
Hello,
I am trying to understand what I am doing wrong?
I am following a step by step youtube video. I don’t understand why it’s not running on Pythonista? I even tried changing the interpreter to 2.7, still not running the code. There is no error message. It’s just not running. The play button blinks when I tap on it or use cmd (r), and nothing happens after that.
Here is the video link:
(I cannot proceed past the 12:50 mark since the code is not running)Here is my code:
import random import time def displayIntro(): print("It is the end of a long year of fighting space criminals") print("you come to a crossroads on your trip home, one path leads home") print("where you will be handsomly rewarded for a job well done") print("and the other leads through a gamma ray burst") def choosePath(): path = "" while path != "1" and path !="2": #input validation path = input("Which path will you choose? (1 or 2): ") return path displayIntro() choosePath()
-
@tactfulgamer as your code was not visible with its indentations...difficult to say if you didn't make an indentation error
This is ok.
Remark that you should insert your code between two lines of triple quotes, in this forum 😀import random import time def displayIntro(): print("It is the end of a long year of fighting space criminals") print("you come to a crossroads on your trip home, one path leads home") print("where you will be handsomly rewarded for a job well done") print("and the other leads through a gamma ray burst") def choosePath(): path = "" while path != "1" and path !="2": #input validation path = input("Which path will you choose? (1 or 2): ") return path displayIntro() p = choosePath() print(p)
-
@cvp said:
import random
import timedef displayIntro():
print("It is the end of a long year of fighting space criminals")
print("you come to a crossroads on your trip home, one path leads home")
print("where you will be handsomly rewarded for a job well done")
print("and the other leads through a gamma ray burst")def choosePath():
path = ""
while path != "1" and path !="2": #input validation
path = input("Which path will you choose? (1 or 2): ")
return pathdisplayIntro()
p = choosePath()
print(p)Thank you!! That was it!!
Does Pythonista have some form of visual indicator to let you know if your indentation is not correct? (I have no idea knowing if my indentation is correct or not) I thought I was following video accurately.
I guess, if Pythonista does not run, that’s pretty much letting me know, the indentation is wrong.
However, would be nice if it pointed out “which of my code lines” needed indentation.
-
@cvp said:
Remark that you should insert your code between two lines of triple quotes, in this forum
Can you please show me what I did wrong?
I tried adding two lines, of triple quotes... and it’s not working.I did this:
‘’’
code
‘’’^^ Not working for me
-
Wrong triple quote. You need the backtick, or press the little </> icon next to the link icon, above the edit box.
-
@JonB Soo much better. Thank you!
-
Sorry, I used erroneously the word quote 😢
-
@tactfulgamer said:
I guess, if Pythonista does not run, that’s pretty much letting me know, the indentation is wrong.
Pythonista would never be able to tell you are wrong if you write
if a == 1: print('a==1') print('here')
instead of
if a == 1: print('a==1') print('here')
Both could be correct...
You only receive an error message "expect an indented block"
if you don't indent a line that needs it..likeif a == 1: print('a==1')
-
Putting in an extra space or leaving one out where it is needed will surely generate an error message . Some common causes of this error include:
- Forgetting to indent the statements within a compound statement
- Forgetting to indent the statements of a user-defined function.
The error message IndentationError: expected an indented block would seem to indicate that you have an indentation error. It is probably caused by a mix of tabs and spaces. The indentation can be any consistent white space . It is recommended to use 4 spaces for indentation in Python, tabulation or a different number of spaces may work, but it is also known to cause trouble at times. Tabs are a bad idea because they may create different amount if spacing in different editors .