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 8931805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:11:41+00:00 2026-06-15T09:11:41+00:00

try: num = int(input(Give me an integer between 1 and 100:)) while num >

  • 0
try:
    num = int(input("Give me an integer between 1 and 100:"))
    while num > 100 or num < 1:
        print ("Sorry, that is not an integer between 1 and 100. Try again.")
        num = int(input("Give me an integer between 1 and 100:"))
except:
    print ("Sorry, that is not an integer between 1 and 100. Try again.")
else:
    print ("Thank you for your input")

How do I tell Python to also print “sorry try again” if they entered input such as “pear” or “sd23214”? Thank you.

  • 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-15T09:11:43+00:00Added an answer on June 15, 2026 at 9:11 am

    Just wrap it all in a while loop

    while True:
        try:
            num = int(input("Give me an integer between 1 and 100:"))
            if num > 100 or num < 1:
                print ("Sorry, that is not an integer between 1 and 100. Try again.")
                continue
        except ValueError:
            print ("Sorry, that is not an integer between 1 and 100. Try again.")
        else:
            print ("Thank you for your input")
            break
    

    Most people would probably not use the else clause here

    while True:
        try:
            num = int(input("Give me an integer between 1 and 100:"))
            if num > 100 or num < 1:
                raise ValueError
            print ("Thank you for your input")
            break
        except ValueError:
            print ("Sorry, that is not an integer between 1 and 100. Try again.")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the code that I've written. int num; try { num=100; DoSomething(); System.out.println(num);
try: html = urlopen('http://glbse.com/api/asset/' + asset.name) except: print 'error while updating the price of
try { if (myBoolean) { while (true) ; } else { System.exit(1); } }
try: recursive_function() except RuntimeError e: # is this a max. recursion depth exceeded exception?
try { JSONArray jArray = new JSONArray(result); for(int i=0;i<jArray.length();i++) { JSONObject json_data = jArray.getJSONObject(i);
Try to see which cast is faster (not necessary better): new c++ case or
Using: HTC Legend and HTC Salsa I'm calculating the speed using: while(true) { try
struct dataStruct { const char* s; int num; }; struct Final_struct { int n;
The code is as follow : #include <stdlib.h> int num = 3; // Static
In my object conversion code I have tons of: try { NativeObject.Property1= int.Parse(TextObject.Property1); }

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.