Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8468393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:55:07+00:00 2026-06-10T15:55:07+00:00

I have been working on a code in which I have to write a

  • 0

I have been working on a code in which I have to write a program to simulate what happens when mice enter the kitchen when the traps are set and not set, and it should read in multiple lines of input, which describe what happens in the kitchen.

If the line Set the trap. is entered, then the mouse trap becomes baited. If the line Mouse! is entered, the program should print what happens to the mouse. If the trap was set, print out Trap!. If the trap wasn’t set, print out The mouse escaped.. For all other lines of input, the program should not do anything. as it should keep reading lines from the user until the user enters a blank line. Once a mouse is caught in the trap, the trap cannot be used to catch another mouse unless it has been reset.

So I have made the program but it’s not working for “The mouse escaped”. Can anyone please guide me by seeing my code:

a = raw_input("Enter line: ")
space = ""
trap_set = True
while a != space:
    a = raw_input("Enter line: ")
    if 'Set the trap.' in a:
        trap_set = True
        print "Trap!"
    else:
        if 'Mouse!' in a:
            trap_set = True
            print "The mouse escaped."

I want my program to run like this:

Enter line: Go to the fridge.
Enter line: Set the trap.
Enter line: Go to bed.
Enter line: Mouse!
Trap!
Enter line: 

OR

Enter line: Make some dinner.
Enter line: Wash the dishes.
Enter line: Mouse!
The mouse escaped.
Enter line: Sweep the floor.
Enter line: Set the trap.
Enter line: Mouse!
Trap!
Enter line: Go to bed.
Enter line: 

and this what I am not able to work out.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:55:08+00:00Added an answer on June 10, 2026 at 3:55 pm

    There were a couple of things mixed up here. If you call ‘Mouse!’ on the first call, it will fail because you have to set in the conditionals first.

    a = raw_input("Enter line: ")
    space = ""
    # did you want to pre-set the trap to True? #
    trap_set = False 
    while a != space:
        if 'Set the trap.' in a:
            trap_set = True
          # no reason to print trap if just setting #
          #  print "Trap!" #
        elif 'Mouse!' in a: 
            if  trap_set == False:
                print "The mouse escaped."
            elif trap_set == True:
                print 'trap'
                trap_set = False
        a = raw_input("Enter line: ")
    

    The last two conditionals are where you are checking to see if the ‘trap’ was set when your ‘mouse’ was entered. Then reset the trap.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code which as been working against an older Active Directory server and
I have been trying to write a program for transferring a file which the
I have been working on some code to submit an uploaded image to PHP
Hi I have been working on this code that creates a table with radio
I am new to github. I have been working on a code that I
I have been working on information extraction and was able to run standAloneAnnie.java http://gate.ac.uk/wiki/code-repository/src/sheffield/examples/StandAloneAnnie.java
I have been working on a Java project in which the reports will be
I am working on a short java assignment that I have been set. The
I've set up a simple, single-service server which has been working just fine with
I am working in a Python program with Javascript and DB. I have been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.