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

  • SEARCH
  • Home
  • 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 4123156
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:34:31+00:00 2026-05-20T23:34:31+00:00

I know all my questions are really easy but I’m a beginner so here

  • 0

I know all my questions are really easy but I’m a beginner so here it is…
I have been developing the guessing number thing after everyones help, but I want to then return to a menu which has just been left. Here’s the code:

import time
import random
animalmenu()

def animalmenu():
    print()
    print()
    print()
    print()
    print('Welcome to the menu. I am thinking of a menu. Select the option\'s below to       try and guess my animal.')
    print()
    print('a) No. of Legs')
    print('b) Type of animal')
    print('c) Preffered Climate')
    print('d) Size')
    print('e) Colour')
    print('f) Diet')
    print('g) Habitat')
    print('h) Can be kept as pet')
    print('i) Guess animal')
    print()
    print('When in a menu, type in \'555\' to return here')
    AniChoice = input('Choose your option: ')
    if AniChoice == 'a':
        loop = 10
        while loop == 10:
            print()
            print('')
            print()
            guessleg = int(input('Guess the number of legs: '))
            if leg == guessleg:
                print('True')
            elif leg != guessleg:
                print('False')
             print('r = Return to menu, g = guess again.')
             rg = input()
             if rg == 'g':
                 print('Loading...')
             elif rg == 'r':
                 loop = 0
                 time.sleep(1)
                 print('Returning to menu...')
                 time.sleep(1)
                 animalmenu()

everytime I run it, I type in a number as the code asks but then, instead of asking if I want to return to the menu it just asks the question again and again, ‘Guess the number of legs: ‘. I know this is something to do with my looping method but I do not understand and because of the integer setting I cannot just make another if, like so:

            guessleg = int(input('Guess the number of legs: '))
            if leg == guessleg:
                print('True')
            elif leg != guessleg:
                print('False')
            elif guessleg == 'back':
                    loop = 0                    
                animalmenu()

And I do not see any other way of doing it as neither way seems to work? How would you suggest returning to animalmenu()?

  • 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-05-20T23:34:32+00:00Added an answer on May 20, 2026 at 11:34 pm

    As the message is telling you, ‘back’ is not an integer, but you are comparing it to a variable into which you have put an integer value. Specifically, your line:

    guessleg = int(input('Guess the number of legs: '))
    

    puts an integer value into guessleg (or more properly tries to) from the user’s input.

    One approach to resolve this is to capture the user’s input in a string variable, compare that string to ‘back’ first, and then convert to an integer if needed.

    Another approach is to wrap a try/except around the integer conversion and proceed with the integer check if the conversion is successful and with the check against ‘back’ if the exception is encountered. This is probably preferred these days and I’ve put it into code:

    inp_val = raw_input('Guess the number of legs: ')
    try:
        guess_num = int(inp_val)
        if guess_num == leg:
            print('True')
        else:
            print('False')
    except ValueError:
        if inp_val == 'back':
            loop = 0
        else:
            print 'Invalid entry'
        animalmenu()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this isn't strictly a programming question but y'all must have experienced this.
I know similar questions have been asked in relation to animating items within an
I don't know if I have all the information needed to phrase this question
We all know how to use <ctrl>-R to reverse search through history, but did
We all know what virtual functions are in C++, but how are they implemented
I have never used SN or Git but I really want to start. I
I'm sure this question HAS to have been asked, but after searching through the
I wish to know all the pros and cons about using these two methods.
We all know T-SQL's string manipulation capabilities sometimes leaves much to be desired... I
We all know that RAW pointers need to be wrapped in some form of

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.