I'm going through a Book which, at this point in the book, requires me to make a small videogame that calls functions, uses if's, while's -- essentially all the things covered in the book so far. But, I get this error in this part of my code:
Code edited, get a new error.
File "ex35_study.py", line 24
third_scenario_code()
IndentationError: unindent does not match any outer indentation level
Here is my code:
options_thirdscenario_actions = ['Examine the door', 'Try to force it']
def third_scenario_code():
print "Let me try to crack this thing up, says Lars as he starts to type in the panel. You hear the sounds of the fight out there, there's not much time left. "
print "After receiving several commands a window with a code pop ups. "
print codefile.read()
def third_scenario():
print "You two get out of the cell and approach to the exit, a long corridor is ahead of you, flashing red lights indicate an state of emergency, you must evacuate."
print "As soon as you two approach to the door, it closes"
print "Crap it must be the emergency system, we have been detected"
next = raw_input("What do you do> ")
if next == 'Examine the door':
print "A small panel comes out, requires to enter a code of words"
third_scenario_code()
elif next == 'Try to force it':
print "You try to force the door with no result"
print options_thirdscenario_actions
next2 = raw_input("What else do you do> " )
if next2 = 'Examine the door'
third_scenario_code()
else:
print "You already did that"
I am getting a similar error on the whole program and I suspect it has something to do with indentation, but I have tried every suggestion I see in google with no fruitful result. thanks in advance.
You are missing colons after the one of if conditions and need to line things that are the same scope up, i.e. the print after the function call but you may also be mixing spaces and tabs. It is recommended to always use 4 spaces rather than tabs and most programming editors can be set up for this.
I would also suggest getting hold of pylint and using it. It will help you spot a lot of potential errors and will help you to develop good habits.
Its because of the indentation of third_scenario_code() you need to write it under the print .
change the following :
if next == 'Examine the door':
print "A small panel comes out, requires to enter a code of words"
third_scenario_code()
to :
if next == 'Examine the door':
print "A small panel comes out, requires to enter a code of words"
third_scenario_code()
Related
after learned while loop and if, i m trying to make a super simple text game, but here is the problem: after the input line asked to type right/left, and no matter i type left or right, the code wont work. i changed the "choice" variable to left then it's working properly... I dont know what's the problems here...please tell me how to fix this to make it work.
choice=str(input("you are now in a forest, please pick a direction(left or right)"))
while choice == "right":
print("a strange wind had sent you back to forest")
choice=str(input("you are now in a forest, please pick a direction(left or right)"))
if choice == "left":
print("u saw a cave, in or not?")
choice= str(input("type in or not "))
if choice == "in" :
print("u saw a bear claw and that's the last view in your eyes")
elif choice == "not":
print("after two and a half hours walking, you are now out of the forest")
that's the code, I think the input line got some problems but I don't know what exact problems are. when I change to choice="right" or choice="left", the code is working but with this input line it's not...
This code is working for me; are you using all lowercase left or right with no quotes or other characters? You may want to add a .lower().strip() to the end of your input call to lowercase everything and remove leading/trailing whitespace.
sorry guys I just found out why!
I have the habit to type a space between words which makes sentences clear but in this case, i type space+left/right and the while loop or if loop is looking for only "left' or "right" so I gave them a input they cannot recognize... that's stupid...
I am so sorry
thank you all for the help tho!
I'm new to programming and don't know what this means. Please tell me what to do to my code for my assessment. It doesn't highlight the problem when I run it and I don't know what to do. Please help me.
To be honest, reading a Python tutorial would probably do you better. In any case, however...
Python is an indentation-based language. This means anytime you enter a new "block" (code that belongs to a statement), you need to indent your code by one level. Here are two examples, one incorrect and one correct:
if 5 < 10:
print "5 is less than 10! Wow! Thanks, math!"
print "I'm so glad Python told me."
This is a syntax error, since the print statement belongs to the if statement, and is therefore a new block. It should be indented, but in this case it wasn't, so it's an error.
if 5 < 10:
print "5 is less than 10! Wow! Thanks, math!"
print "I'm so glad Python told me."
print "This is printed in any case, since it doesn't belong to the above block."
Here is the fixed verion. Notice the four spaces in the beginning of the second line? That's called "indentation". Any subsequent lines indented to the same level will be part of the block. Generally, you press TAB to indent in your text editor. The last line, however, is not indented and will therefore run regardless of whether the if statement evaluates to True or not.
Hello I am a fairly novice programmer. And I have a simple code
name=raw_input("Hello I am Bob. What is your name?")
print("It is very nice to meet you,", name)
response=raw_input("what do you want to do today?")
if response == "price match":
However on the fourth line I get SyntaxError: unexpected EOF while parsing error and I did look into it and I found that using the raw_input for inputted strings is much better than using the input function.I don't know why the error keeps popping up. Could I get some help and perhaps some suggestions as to how I can improve the code.
You have to do something in the if statement. For example, print a price:
if response == "price match":
print "Yes, we can do that for you".
But, you can't just leave a block (the stuff that is indented after a :) empty, or Python will give you an error.
In rare cases (and not in your case here), you may want to do absolutely nothing, but still have a block (e.g. if required to by an except:). In that case, you still have to put something in the block, but you can use the word pass which does nothing. (This is almost never used in an if block).
I'm no Python expert.. But it looks like your problem is here:
response=raw_input("what do you want to do today?") if response == "price match":
You are defining an if statement, but if this value is true, how do you handle it?
I'm guessing you would need something like:
if response == "price match":
print('Match')
else:
print('Did not match')
Hope this helps a little
If you need a placeholder for just having valid syntax before putting in the body of your if/else/functions/etc, use pass.
http://docs.python.org/release/2.5.2/ref/pass.html
As for your code, a valid if statement must always have a body. So put some code there or use pass.
Im having problem running my little interactive story i wrote in python. I keep running into some sort of NON-ASCII error or some sort that doesnt let me run the program.
Heres the program if you want to try it: [Program][1]
Here's my code:
#Programmer: 11/8/12
# Story of Doors
# Interactive story where the user can choose between options in between the - - marks.
def main():
print "I welcome you to the mind of the chosen. A place only understood by those who never forfeit. The chance to walk through the halls is given only but once the time has come for you to decide, will you stand aside, or never regret to have tried?"
#Quest is the word used to decide whether the player wants to play or quit.
Quest = raw_input(" I welcome you to the mind of the chosen. A place only understood by those who never forfeit. The chance to walk through the halls is given only but once the time has come for you to decide, will you stand aside, or never regret to have tried?")
if(Quest == "stand aside"):
print "Have fun asleep, for those who will awake are the ones who take the leap."
if (Quest == "never regret to have tried"):
print "I see you think yourself as worthy, I hope you know, this quest is full of low beings"
print "Down the hall you walked with a line of doors not covered or locked. The choices are at hand with many experiences to be had."
print "Step into a door and never look back, for your decisions will open a crack. Your choices are at hand, choose from the list written in sand."
#here the reader\player decides what quest he wants to go on, or what door they want to open.
Opendoor = raw_input("Door 1: The door of no troubles where you see everything in doubles ") + ("Door 2: ")
if(Opendoor == "Door 1"):
print "The incense infilled maple shaped door was entered to the begin the scene."
print "Going straight through to a land engulfed by the waves controlled, where the shore is seen when the machines flee."
print "Out through a mix of purple and green lies The Beheaded Dragon who whispers and schemes. 'Come to my lab, and enjoy the lick of a colorful tab.'"
print "After a flash of happy and sad, you see through perspectives and forget the word 'bad'."
print "With witches and crafts, comes the great Sage whose be riddled with mad."
print " I know of a place where the sky is purple and nobodies hurtful heaven at night is spoken of. The minds are torn up with a thought of what’s next."
ComeAlong = raw_input(" Will you -join the quest- or -eschew the test-? ")
if(ComeAlong == "eschew test"):
print "'I accept your decline and reply with a good-bye.'"
if(ComeAlong == "join quest"):
print "'I'm glad you see yourself as worthy, just remember kid, in here. No mind is sturdy.'"
print " Here begins a trip to the land of nomads where you witness a dance and give it a try, for you have no doubts as you see with one eye. Forgotten stories of the times of war, for the children are busy learning to soar."
print "you join this man with not but one rule 'never turn back, for there are consequences for trying to hack.'"
print "'This is a place of glitches and traps, but the end lies open with stitches to map'"
Woman = raw_input(" You journey onward through the forest and trees but come across some women on their knees their eyes are locked and only you hold the keys. You're given the choice to open the lock and -allow them to see- or leave them locked and -mimick the birds and the bees-.")
if(Woman == "mimick the birds and the bees"):
print "You approach the women and accept their tease. They looks up at you with a smile, and simultaneously screech 'We see your story has ended and can now be marked as 'deceased' and within a blink of an eye you are paralyzed with nothing to drink."
wait(2)
print "Nice try, but this saddly proves, you're not ready to fly. and with that I wave to you a sincere and heart felt good-bye!"
if(Woman == "allow them to see"):
print " You approach the women and give them the keys, they grabs them and begin to flee but while the flock reaches there caves one of the women stands beside you and opens the lock."
print " 'I know where your headed and can lend you my boat, it's right around the corner sitting by the dock.'"
print " As you follow the woman you look up onto the sky and read aloud 'Take a deep breath and watch your step' confused by the words you ask the woman 'Hey, whats that mean?' with no response you look down to her but see nothing but a stream"
print " 'Hello!?' you scream, but no one is to be seen. All alone you begin to gleam followed by your lungs releasing the steam"
print " With that the scene darkens and you rise from your sleep, just to realize life, is but a dream."
# Second Door of choices.
if(Opendoor == "Door 2"):
print "This is a story of a young wounded boy, who was lost in his mind with one little toy. He sat on the floor waiting for more, but after an hour his feelings went sour."
print "He rose up on his feet and started to wonder. Through the bright door there were tons of new people to meet."
print " He made it his duty to connect with these people, even if they were him in a past life or sequel."
print " After some time came a decision. To speak with -the man in the white-, or -the woman with no sight-"
if(Decision == "the man in the white"):
print " 'Hello mister. May i ask you some questions?'"
print " 'Why yes you may, but i dont have time to give you a lesson.'"
print " 'They will be quick i promise, What brings you here to the land of nostradamus?'"
print " ' Well isnt it obvious? Nothing more than the thirst for knowledge!'"
print " 'Ahh I see, but what do you do if you cant find the answer to the riddle you speak?'"
print " 'Then I learn a new language and ask it to Nietzsche' "
print " 'What if its a question with no answer?'"
print "' Then I forget about philosophy and become a great dancer! But in all seriousness, you musn't forget for every box of questions there is box of answers'"
if(Decision == "the woman with no sight"):
print " 'Hello miss, do you have some free time?'"
print " ' Ofcourse I do, and i'll give you it for a dime' "
print " 'If I pay it is not free ' "
print " 'it's a reward, not a fee.'"
print " ' okay but if i dont enjoy what you have to say will I still have to pay?'"
print " ' I'm sorry but you pay for the herbs, not the tea.'"
print " 'I understand the concept, but i'll have to disagree.'"
main()
This is the first time I use StackOverflow so if there is anything else I could do to help you guys help me please let me know.
On line 28, you have the character ’, which is not an ASCII character. You need to replace that character with '. That will let the program run without errors. In the future, if you run into similar errors, you can use the following command to grep for non-ASCII characters:
grep --color='auto' -P -n "[\x80-\xFF]" your_file.py
Second, you need to put the call to main() within the global scope (i.e. it should not have any indentation before it). Right now, it is nested within a conditional and will not be executed when the Python interpreter reads the main body of the file.
You didn't mention what version of Python this is, but I'm guessing 2.7 (it's definitely not 3.x).
When I save this as a file and run it in 2.7, I get this:
SyntaxError: Non-ASCII character '\xe2' in file ./if.py on line 30, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
This means exactly what it says. In Python 2.7, if you want to type any non-ASCII characters in a string literal—even just things like é—you must provide an encoding declaration. Read the URL in the error message to see how to do that.
The alternative is to escape the characters. Instead of typing "Abré", you type "Abr\xe9"—or, better, u"Abr\u00e9"—and it'll work
Meanwhile, either way, you almost certainly want the strings to be Unicode strings, not 8-bit strings. That means instead of "Foo", you want u"Foo" everywhere.
I'm making a game in Python (text only) but it gets confusing when people play it because there is no space between the paragraphs, so it looks like this:
'You step outside and feel the wind on your face.'
'Which direction do you turn?'
But I would like it to look like this:
'You step outside and feel the breeze on your face'
'What do you do next'?
Here's my code:
print 'You step outside and feel the cool breeze on your face.'
what = raw_input ('What do you do next ')
Thanks!
Print a newline character.
print("\n")
Or:
print("An angry-looking dwarf throws an axe at you.\nYou die.\n")
You have a few solutions:
The simpler one would be to use a print statement between your lines, which, used alone, prints a line feed.
Alternatively, you could you end the string you're printing with a '\n' character, which will cause a line feed, or you could start your input with the same character.
print('\v')
vertical tab for vertical space.