Python Forum
General Grok Help - 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: General Grok Help (/thread-21017.html)



General Grok Help - AmineLS - Sep-10-2019

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


RE: General Grok Help - SheeppOSU - Sep-10-2019

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-Adventure-Tutorial-if-structure-to-dictionary


RE: General Grok Help - AmineLS - Sep-11-2019

 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


RE: General Grok Help - SheeppOSU - Sep-11-2019

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


RE: General Grok Help - AmineLS - Sep-11-2019

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


RE: General Grok Help - SheeppOSU - Sep-11-2019

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"