Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
General Grok Help
#1
if room == "middle":
  print("Actions available: forward, backward, look")
  action = input("> ")
  if action == "forward":
    room = "end"
  elif action == "backward":
    room = "start"
  else:
    room = "middle"
This is the output:
Output:
Actions available: forward, look > look You are standing at the entrance to a long tunnel. Actions available: forward, look > forward You are in the depths of the tunnel. Actions available: forward, backward, look > backward You are standing at the entrance to a long tunnel. Actions available: forward, look > forward You are in the depths of the tunnel. Actions available: forward, backward, look > look You are in the depths of the tunnel. Actions available: forward, backward, look > forward You have escaped the tunnel. You win!
I am currently studying Grok The Dark Tunnel (Python)
Hour of Code: The Dark Tunnel, spent quiet some time, if anyone is able to point out what i am missing or misplaced please help, iv been getting so many syntax errors I really need your help guys !

Huh Idea Idea Angel
Reply
#2
Please post the error. Full code would help, and this forum has a tutorial for efficiently making a text adventure game here - https://python-forum.io/Thread-Text-Adve...dictionary
Reply
#3
 if room == "You are in the depths of the tunnel.":
  print("Actions available: forward, backward, look")
  action = input("> ")
  if action == "forward":
    room = "You have escaped the tunnel. You win!"
  elif action == "backward":
    room = "You are standing at the entrance to a long tunnel."
  print('Actions available: forward, backward, look')
  action = input("> ")
  else: "forward"
    room = "You are in the depths of the tunnel."
  print('You have escaped the tunnel. You win!')
Error:
File "program.py", line 10 else: "forward" ^ SyntaxError: invalid syntax
Output:
Actions available: forward, look > forward You are in the depths of the tunnel. Actions available: forward, backward, look > forward You have escaped the tunnel. You win!
Output:
Actions available: forward, look > look You are standing at the entrance to a long tunnel. Actions available: forward, look > forward You are in the depths of the tunnel. Actions available: forward, backward, look > backward You are standing at the entrance to a long tunnel. Actions available: forward, look > forward You are in the depths of the tunnel. Actions available: forward, backward, look > look You are in the depths of the tunnel. Actions available: forward, backward, look > forward You have escaped the tunnel. You win!
So.. I am starting to get the hang of this forum messaging protocols and I like how it just makes everything organized. So This is what I got after hours of head scratching ! Lol *Edit, the python feature is not showing up ?
 
isnt working
Reply
#4
The spacing is wrong. Lines 8-9 end the if statement, so the else is seen as a lone else statement with no if to relate to. Either move lines 8-9 up into the elif statement, or move them after the else statement depending on how it is supposed to work
Reply
#5
I don't even think what I did was right. I tried following your advice and I'm still confused.. bare with me please I am a newbie Wall I appreciate your reply! I need to find a solution please
Reply
#6
I'll just give you some examples and you can use them to fix your code.
#Here is an if statement
if #Statement
    #Code
elif #Statement
    #Code
#Code - this code here ends the statement. The if statement will not look past this for anything
else #Python thinks this else is just here with no if to relate to
I hope this helps you see what's wrong with your code

Where i put "#Code", just imagine there is code there and statements where it says "#Statement"
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  GROK MODULE 5 HELP! AmineLS 1 8,501 Sep-26-2019, 04:21 PM
Last Post: metulburr
  New programmer using GROK AmineLS 2 3,124 Sep-10-2019, 12:25 PM
Last Post: AmineLS

Forum Jump:

User Panel Messages

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