Bottom Page

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
Quote
#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
Age Doesn't Matter, Your Passion Does
- Shreya Jain
Quote
#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
Quote
#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
Age Doesn't Matter, Your Passion Does
- Shreya Jain
Quote
#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
Quote
#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"
Age Doesn't Matter, Your Passion Does
- Shreya Jain
Quote

Top Page

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

Forum Jump:


Users browsing this thread: 1 Guest(s)