Rewrite the code so break isn't needed for the riddles

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Rewrite the code so break isn't needed for the riddles

def townSquare():
I?
print("You're in Town Square ")
print("Solve this riddle to move ahead. >
def
ans=""
11
while(ans!="temper" or ans!="a temper"):
input("'The shorter I am, the bigger I am. What am I?'").lower(
if(ans=="temper" or ans==' a temper"):
print("Correct! You may now proceed.")
ans
answer! Try again.")
print("Type 'Northeast' or 'NE' to go to the Town Hall")
print("Type South' or 'S' to go to the Town Archives")
print("Type Southeast' or SE' to go to the Trading Post")
nextRoom =
while(nextRoom
userInput
ans=
else:
for Trading Post")
break
input("Player choice: ").upper()
if(userInput== "NORTHEAST" or userInput=="NE"):
nextRoom
print(nextRoom)
print("Incorrect
"Town Hall"
elif(userInput=="SOUTH" or userInput=="S"):
nextRoom = "Town Archives"
elif(userInput=="SOUTHEAST" or userInput=="SE"):
nextRoom =
elif(userInput
return nextRoom
elif(userInput
else:
def tradingPost():
print("Welcome! You're in the Trading Post.")
ans =
).lower()
ans=
"Trading Post"
'HELP'):
print("NORTHEAST for Town Hall, SOUTH for Town Archives, or SOUTHEAST
while(ans!="trouble" or ans!="Trouble"):
caterer
else:
' LOOK ):
print("You're in Town Square. >
print("Command unrecognize.")
while(nextRoom
userInput
ans='
print("You found a key.")
print("type 'Northwest' or
nextRoom
if(ans=="trouble" or ans=="Trouble"):
print("Correct! You may now proceed.
11 11
11 11
break
elif(userInput
else:
print(nextRoom)
return nextRoom
elif(userInput
ans=
print("Incorrect answer! Try again.")
input("Player choice: ").upper()
if(userInput=="NORTHWEST". or userInput=="NW") :
nextRoom = "Town Square"
else:
while(nextRoom
userInput
Game.")
nextRoom
secretRoom():
print("Welcome! You're in the Secret Room.")
input("'I'm easy to get into, but hard
break
else:
while(ans!="Silence" or ans!="silence"):
ans = input("'Say my name and I disappear. What
if(ans=="Silence" or ans=="silence"):
print("Correct! You may now proceed.")
print(nextRoom)
def townArchives()
print("Go NORTHWEST to Town Square")
.
return nextRoom
LOOK'):
print("You're in the Trading Post.")
print("Command unrecognize.")
print("Incorrect answer! Try again.")
print("Go to the Study and type Pull Book.")
print("Type 'North' or 'N' to go to the Study.")
nextRoom
nextRoom
elif(userInput
ans="
else:
elif(userInput
nextRoom
11 11
while(nextRoom
userInput
break
=
else:
if(userInput=="NORTH" or userInput=="N"):
def garden():
print(nextRoom)
return nextRoom
11 11
else:
=
print("Welcome! You're in the Town Archives.
while(ans!="tree" or ans!="a tree"):
ans =
input( Born underground, raised by the
of fun. What am I?'").lower()
if(ans=="tree" or ans== ="a tree"):
print("Correct! You may now proceed. >
11 11
nextRoom =
elif(userInput
HELP'):
print("Go NORTH for Study")
'LOOK'):
print("You're in the Secret Room.")
print("Command unrecognize.")
elif(userInput
nextRoom
break
while(nextRoom
userInput
""):
print("Type 'South' or 'S' to
else:
==
def endRoom():
===
11 11
==
print("Incorrect answer! Try again.")
to the Study.")
print(nextRoom)
return nextRoom
=
11
else:
if(userInput=="SOUTH" or userInput=="S"):
'>
==
elif(userInput
==
break
input("Player choice: ").upper()
'HELP'):
print("Go SOUTH for Study")
'LOOK'):
print("You're in the Town Archives. >
print("Command unrecognize.")
print("Welcome! You're in the Garden.")
ans =
while(ans!="hole" or ans!="a hole"):
input("'I am weightless, but
and I'll make it lighter. What am I?'").lower(
if(ans=="hole" or ans=="a hole"):
print("Correct! You may now proceed. >
"):
===
11 11
while(nextRoom
userInput
else:
●
11 11
▼
"Study"
print("Type 'East'
==
==
print("Incorrect answer! Try again.")
print("Type 'West' or 'W' to go to the Dead End and return
Southeast' or 'SE' to return to the Town Square.")
print(nextRoom)
▼
'HELP'):
return nextRoom
""):
'W"):
input("Player choice: ").upper()
if(userInput=="WEST" or userInput=
nextRoom = "Car Ride"
nextRoom
elif(userInput
NW
input("Player choice: ").upper()
elif(userInput
"Study"
==
elif(userInput=="SOUTHEAST" or userInput=="SE"):
nextRoom = "Town Square"
'LOOK'):
print("You're in the Garden.")
""):
to go to Town Square. >
print("Command unrecognize.
'HELP'):
print("Go WEST for Car Ride or SOUTHEAST for Town
elif(userInput
==
==
print("Winner!")
def cultChambers():
print("Welcome! You're in the Cult Chambers.")
go
The first runs and never wearies. The second eats and
drinks and is always thirsty. The fourth sings a song
if(ans=="water, fire, earth, wind." or ans=="Water,
print("Correct! You may now proceed.")
'E'
or
""):
print("Incorrect answer! Try again.")
==
11
to
while(ans!="water, fire, earth, wind" or ans!= "Water, Fire, Earth, Wind"):
ans =
input( 'There are four siblings in this world, all born together.
is never full. The third
==
.
11
go
"End Room"
'HELP'):
11
print("Go EAST or SOUTH")
if(userInput=="EAST" or userInput=="E"):
print("Dead End")
elif(userInput=="SOUTH" or userInput=="S"):
to get out of. What am
you can see me. Put me
input("Player choice: ").upper()
LOOK'):
print("You're in the Cult Chambers
print("Command unrecognize. >
to the Dead End
am
sun,
I? > lower(
a host for the
in
Square.
or 'South'
a
to the Car Ride or
forever. ").lower()
or
living,
bucket,
Fire, Earth, Wind"):
·S
to End
Transcribed Image Text:def townSquare(): I? print("You're in Town Square ") print("Solve this riddle to move ahead. > def ans="" 11 while(ans!="temper" or ans!="a temper"): input("'The shorter I am, the bigger I am. What am I?'").lower( if(ans=="temper" or ans==' a temper"): print("Correct! You may now proceed.") ans answer! Try again.") print("Type 'Northeast' or 'NE' to go to the Town Hall") print("Type South' or 'S' to go to the Town Archives") print("Type Southeast' or SE' to go to the Trading Post") nextRoom = while(nextRoom userInput ans= else: for Trading Post") break input("Player choice: ").upper() if(userInput== "NORTHEAST" or userInput=="NE"): nextRoom print(nextRoom) print("Incorrect "Town Hall" elif(userInput=="SOUTH" or userInput=="S"): nextRoom = "Town Archives" elif(userInput=="SOUTHEAST" or userInput=="SE"): nextRoom = elif(userInput return nextRoom elif(userInput else: def tradingPost(): print("Welcome! You're in the Trading Post.") ans = ).lower() ans= "Trading Post" 'HELP'): print("NORTHEAST for Town Hall, SOUTH for Town Archives, or SOUTHEAST while(ans!="trouble" or ans!="Trouble"): caterer else: ' LOOK ): print("You're in Town Square. > print("Command unrecognize.") while(nextRoom userInput ans=' print("You found a key.") print("type 'Northwest' or nextRoom if(ans=="trouble" or ans=="Trouble"): print("Correct! You may now proceed. 11 11 11 11 break elif(userInput else: print(nextRoom) return nextRoom elif(userInput ans= print("Incorrect answer! Try again.") input("Player choice: ").upper() if(userInput=="NORTHWEST". or userInput=="NW") : nextRoom = "Town Square" else: while(nextRoom userInput Game.") nextRoom secretRoom(): print("Welcome! You're in the Secret Room.") input("'I'm easy to get into, but hard break else: while(ans!="Silence" or ans!="silence"): ans = input("'Say my name and I disappear. What if(ans=="Silence" or ans=="silence"): print("Correct! You may now proceed.") print(nextRoom) def townArchives() print("Go NORTHWEST to Town Square") . return nextRoom LOOK'): print("You're in the Trading Post.") print("Command unrecognize.") print("Incorrect answer! Try again.") print("Go to the Study and type Pull Book.") print("Type 'North' or 'N' to go to the Study.") nextRoom nextRoom elif(userInput ans=" else: elif(userInput nextRoom 11 11 while(nextRoom userInput break = else: if(userInput=="NORTH" or userInput=="N"): def garden(): print(nextRoom) return nextRoom 11 11 else: = print("Welcome! You're in the Town Archives. while(ans!="tree" or ans!="a tree"): ans = input( Born underground, raised by the of fun. What am I?'").lower() if(ans=="tree" or ans== ="a tree"): print("Correct! You may now proceed. > 11 11 nextRoom = elif(userInput HELP'): print("Go NORTH for Study") 'LOOK'): print("You're in the Secret Room.") print("Command unrecognize.") elif(userInput nextRoom break while(nextRoom userInput ""): print("Type 'South' or 'S' to else: == def endRoom(): === 11 11 == print("Incorrect answer! Try again.") to the Study.") print(nextRoom) return nextRoom = 11 else: if(userInput=="SOUTH" or userInput=="S"): '> == elif(userInput == break input("Player choice: ").upper() 'HELP'): print("Go SOUTH for Study") 'LOOK'): print("You're in the Town Archives. > print("Command unrecognize.") print("Welcome! You're in the Garden.") ans = while(ans!="hole" or ans!="a hole"): input("'I am weightless, but and I'll make it lighter. What am I?'").lower( if(ans=="hole" or ans=="a hole"): print("Correct! You may now proceed. > "): === 11 11 while(nextRoom userInput else: ● 11 11 ▼ "Study" print("Type 'East' == == print("Incorrect answer! Try again.") print("Type 'West' or 'W' to go to the Dead End and return Southeast' or 'SE' to return to the Town Square.") print(nextRoom) ▼ 'HELP'): return nextRoom ""): 'W"): input("Player choice: ").upper() if(userInput=="WEST" or userInput= nextRoom = "Car Ride" nextRoom elif(userInput NW input("Player choice: ").upper() elif(userInput "Study" == elif(userInput=="SOUTHEAST" or userInput=="SE"): nextRoom = "Town Square" 'LOOK'): print("You're in the Garden.") ""): to go to Town Square. > print("Command unrecognize. 'HELP'): print("Go WEST for Car Ride or SOUTHEAST for Town elif(userInput == == print("Winner!") def cultChambers(): print("Welcome! You're in the Cult Chambers.") go The first runs and never wearies. The second eats and drinks and is always thirsty. The fourth sings a song if(ans=="water, fire, earth, wind." or ans=="Water, print("Correct! You may now proceed.") 'E' or ""): print("Incorrect answer! Try again.") == 11 to while(ans!="water, fire, earth, wind" or ans!= "Water, Fire, Earth, Wind"): ans = input( 'There are four siblings in this world, all born together. is never full. The third == . 11 go "End Room" 'HELP'): 11 print("Go EAST or SOUTH") if(userInput=="EAST" or userInput=="E"): print("Dead End") elif(userInput=="SOUTH" or userInput=="S"): to get out of. What am you can see me. Put me input("Player choice: ").upper() LOOK'): print("You're in the Cult Chambers print("Command unrecognize. > to the Dead End am sun, I? > lower( a host for the in Square. or 'South' a to the Car Ride or forever. ").lower() or living, bucket, Fire, Earth, Wind"): ·S to End
def underGroundCave():
print("Welcome! You're in the Under Ground Cave.")
print("Type South' or 'S' to go to the Cult Chambers")
nextRoom
while(nextRoom
userInput
def study():
else:
print(nextRoom)
if(userInput=="SOUTH" or userInput=="S"):
return nextRoom
11 11
elif(userInput
elif(userInput
while(nextRoom
userInput
nextRoom = "Cult Chambers"
'HELP'):
print("Go_SOUTH for Cult Chambers")
'LOOK'):
print("You're in the Under Ground Cave.")
print("Command unrecognize.")
print("Welcome! You're in the Study.")
print("Type 'Pull Book' or 'PB' to go to the Underground Cave")
nextRoom
else:
print(nextRoom)
def mansion():
elif(userInput
return nextRoom
input("Player choice: ").upper()
if(userInput=="PULL BOOK" or userInput=="PB"):
nextRoom =
"Underground Cave"
elif(userInput
'HELP'):
nextRoom
while(nextRoom
userInput
=
room
main()
print("Pull a book for Underground Cave")
'LOOK'):
print("You re in the Study.")
else:
nextRoom
print("Welcome! You're in Mansion.")
print("Type 'West' or 'W' to go to the Garden")
print("Type 'North' or 'N' to go to the Study")
print("Type 'Key' or 'K' to enter the Secret Room.")
nextRoom
print(nextRoom)
return nextRoom
while(nextRoom
userInput
nextRoom
elif(userInput
elif(userInput
==
else:
=
11 11
def main():
in
if(userInput=="WEST" or userInput=="W"):
print(nextRoom)
return nextRoom
while(nextRoom
userInput
elif(userInput== NORTH" or userInput=="N"):
nextRoom
"Study'
11 11
elif(userInput=="KEY" or userInput=="K"):
"1
else:
""):
==
'HELP'):
print("KEY_for Secret Room, WEST for Garden, or NORTH for Study.")
'LOOK'):
print("You're in the Mansion.")
t("Player choice: ").upper()
==
print( Command unrecognize.")
print(nextRoom)
==
=
def townHall():
print("Welcome! You're in the Town Hall.")
print("Type 'West' or 'W' to go to the Mansion.")
nextRoom
""):
==
return nextRoom
""):
==
==
room
input("Player choice: ").upper()
==
if(userInput=="WEST" or userInput=="W"):
nextRoom
elif(userInput
print("Go WEST
elif(userInput
room =
"Car Ride"
elif(userInput
room
""):
'HELP'):
to the Mansion")
'LOOK'):
print("You're in the Town Hall."
print("Command unrecognize.")
==
"Garden"
def carRide():
print("Type 'West' or 'W' to go to the Town Square else South/S, North/N/ or
West/W for random location.")
nextRoom
room =
=
"1
room =
"Secret Room
==
===
input("Player choice: ").upper()
if(userInput=="WEST" or userInput=="W"):
nextRoom
"Town Square"
elif(userInput =="SOUTH" or userInput=="S"):
"Trading Post"
nextRoom =
elif(userInput =="NORTH" or userInput=="N"):
"Garden"
nextRoom =
elif(userInput= =="WEST" or userInput=="W"):
nextRoom
elif(userInput
"Mansion"
==
"1
===
):
input("Player choice: ").upper()
print("Go WEST
11 11
print("You're in the Car Ride.")
print("Command unrecognize.")
"Car Ride"
print("You're in a car. The town of Loveheaven
while(room!=""):
"Underground Cave"
HELP'):
==
if(room=="Car Ride"):
room =
carRide()
==
elif(room=="Town Square"):
for Underground Cave")
'LOOK'):
room =
elif(room=="Trading Post"):
elif(room=="Garden"):
room =
townSquare()
garden()
elif(room =="Underground Cave"):
tradingPost()
elif(room=="Town Hall"):
underGroundCave()
townHall()
elif(room=="Town Archives"):
room =
elif(room=="Secret Room"):
room =
townArchives()
elif(room=="End Room"):
endRoom ( )
secretRoom()
elif(room=="Cult Chambers"):
room =
elif(room=="Study"):
room =
cultChambers()
study (
elif(room= =="Mansion"):
mansion()
is ahead. Can you
escape?")
Transcribed Image Text:def underGroundCave(): print("Welcome! You're in the Under Ground Cave.") print("Type South' or 'S' to go to the Cult Chambers") nextRoom while(nextRoom userInput def study(): else: print(nextRoom) if(userInput=="SOUTH" or userInput=="S"): return nextRoom 11 11 elif(userInput elif(userInput while(nextRoom userInput nextRoom = "Cult Chambers" 'HELP'): print("Go_SOUTH for Cult Chambers") 'LOOK'): print("You're in the Under Ground Cave.") print("Command unrecognize.") print("Welcome! You're in the Study.") print("Type 'Pull Book' or 'PB' to go to the Underground Cave") nextRoom else: print(nextRoom) def mansion(): elif(userInput return nextRoom input("Player choice: ").upper() if(userInput=="PULL BOOK" or userInput=="PB"): nextRoom = "Underground Cave" elif(userInput 'HELP'): nextRoom while(nextRoom userInput = room main() print("Pull a book for Underground Cave") 'LOOK'): print("You re in the Study.") else: nextRoom print("Welcome! You're in Mansion.") print("Type 'West' or 'W' to go to the Garden") print("Type 'North' or 'N' to go to the Study") print("Type 'Key' or 'K' to enter the Secret Room.") nextRoom print(nextRoom) return nextRoom while(nextRoom userInput nextRoom elif(userInput elif(userInput == else: = 11 11 def main(): in if(userInput=="WEST" or userInput=="W"): print(nextRoom) return nextRoom while(nextRoom userInput elif(userInput== NORTH" or userInput=="N"): nextRoom "Study' 11 11 elif(userInput=="KEY" or userInput=="K"): "1 else: ""): == 'HELP'): print("KEY_for Secret Room, WEST for Garden, or NORTH for Study.") 'LOOK'): print("You're in the Mansion.") t("Player choice: ").upper() == print( Command unrecognize.") print(nextRoom) == = def townHall(): print("Welcome! You're in the Town Hall.") print("Type 'West' or 'W' to go to the Mansion.") nextRoom ""): == return nextRoom ""): == == room input("Player choice: ").upper() == if(userInput=="WEST" or userInput=="W"): nextRoom elif(userInput print("Go WEST elif(userInput room = "Car Ride" elif(userInput room ""): 'HELP'): to the Mansion") 'LOOK'): print("You're in the Town Hall." print("Command unrecognize.") == "Garden" def carRide(): print("Type 'West' or 'W' to go to the Town Square else South/S, North/N/ or West/W for random location.") nextRoom room = = "1 room = "Secret Room == === input("Player choice: ").upper() if(userInput=="WEST" or userInput=="W"): nextRoom "Town Square" elif(userInput =="SOUTH" or userInput=="S"): "Trading Post" nextRoom = elif(userInput =="NORTH" or userInput=="N"): "Garden" nextRoom = elif(userInput= =="WEST" or userInput=="W"): nextRoom elif(userInput "Mansion" == "1 === ): input("Player choice: ").upper() print("Go WEST 11 11 print("You're in the Car Ride.") print("Command unrecognize.") "Car Ride" print("You're in a car. The town of Loveheaven while(room!=""): "Underground Cave" HELP'): == if(room=="Car Ride"): room = carRide() == elif(room=="Town Square"): for Underground Cave") 'LOOK'): room = elif(room=="Trading Post"): elif(room=="Garden"): room = townSquare() garden() elif(room =="Underground Cave"): tradingPost() elif(room=="Town Hall"): underGroundCave() townHall() elif(room=="Town Archives"): room = elif(room=="Secret Room"): room = townArchives() elif(room=="End Room"): endRoom ( ) secretRoom() elif(room=="Cult Chambers"): room = elif(room=="Study"): room = cultChambers() study ( elif(room= =="Mansion"): mansion() is ahead. Can you escape?")
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Graphical User Interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education