Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Format for elif
#1
Hi - I am new to Python and was attempting to code based on the guidance at https://www.youtube.com/watch?v=8uJFN7OZ...vF&index=4. I am running into a code format issue with elif (line 35). Can you please help me identify the format issue

import random

def msg(room):
  if room[msg]==' ':
    return "you have entered the " + room['name']+' '
  else:
    return room['msg']

def main():
  dirs = (0,0,0,0)
  entrance = {'name':'Entrance way','directions':dirs,'msg':''}
  livingroom = {'name':'Livingroom','directions':dirs,'msg':''}
  hallway = {'name':'Hallway','directions':dirs,'msg':''}
  diningroom = {'name':'Diningroom','directions':dirs,'msg':''}
  kitchen = {'name':'Kitchen','directions':dirs,'msg':''}
  familyroom = {'name':'Familyroom','directions':dirs,'msg':''}

  entrance['directions'] = (kitchen, livingroom, 0, 0)
  livingroom['directions'] = (diningroom, 0, 0, entrance)
  hallway['directions'] = (0, kitchen, 0, familyroom)
  kitchen['directions'] = (0, diningroom, entrance, hallway)
  diningroom['directions'] = (0, 0, livingroom, kitchen)
  familyroom['directions'] = (0,hallway,0,0)

  rooms = [livingroom,hallway,diningroom,kitchen,familyroom]
  room_with_eggs = random.choice(rooms)
  eggs_delivered = False
  room = entrance 
  print (' can you find the basket')

  while True:
    if eggs_delivered == True and room[name] == 'Entrance way':
      print('you have the basket')
      break;
    elif not eggs_delivered and room['name'] == room_with_eggs['name']:
      eggs_delivered = True   
      print ('There\'s is the basket and Johnny is sleeping' + 'right next to it and! you have delivered the eggs' + 'get out quick')
      room['msg']= ('you are back in the room' + room['name'] + '! you already delivered the eggs' + 'get out of here before Johnny wakes up'  )
    else:
      print(msg(room))
      room['msg'] = 'You are back in the '+ room['name']

      stuck = True
      
main()
Reply


Messages In This Thread
Format for elif - by sunilramakumar - Apr-08-2019, 01:49 AM
RE: Format for elif - by Larz60+ - Apr-08-2019, 03:00 AM
RE: Format for elif - by sunilramakumar - Apr-08-2019, 10:38 AM
RE: Format for elif - by Larz60+ - Apr-08-2019, 05:10 PM
RE: Format for elif - by Yoriz - Apr-08-2019, 05:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Whats the right way to refactor this Big if/elif/elif ? pitosalas 1 2,278 Jul-28-2019, 05:52 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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