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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:23:23+00:00 2026-06-04T06:23:23+00:00

I am writing a program where a user inputs a number in base 10

  • 0

I am writing a program where a user inputs a number in base 10 to be converted into that number in a different (or same) base.

def convert(a,b)

Where a is the input and b is the new base. I am instructed to have the program return the value “-1” if b is not an integer, if b assumes no value (ie blank), or if b is an integer that is less than 1.

I know how to convert the number, and I know how to have the program return -1 if b is less than 1, but how do I get the program to return -1 if b is empty or not an integer?

  • 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-04T06:23:24+00:00Added an answer on June 4, 2026 at 6:23 am

    Short answer: Don’t.

    Type checking is not Pythonic. Try doing what you want to do, and if it works, it works, if it doesn’t, it throws an exception.

    Likewise, returning -1 on failure is not very Pythonic, generally, you want to throw an exception on a failure. There are some (rare) cases where this makes sense, but in general it means that you have to check the value (rather than just catching the exception where needed) and makes for a harder to spot bug (the value is -1 rather than getting an exception).

    Long answer: If you really need to, then you can use isinstance(value, int) to check if a value is an integer, however, this undermines Python’s duck-typing, and is therefore a bad idea 99.9% of the time. It also doesn’t necessarily work how you expect – for example, bool is a subclass of int, so isinstance(True, int) will return True – which may or may not be what you want.

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

Sidebar

Related Questions

I'm writing a program that gathers user input for two file names, and opens
I was writing a program that tell the user to input a random string,
I am writing a C++ program that prompts the user for an input and
I am writing a program that takes in an input file from the user.
I'm writing a tiny program that takes user input using Getops, and based on
I'm just learning COBOL; I'm writing a program that simply echos back user input.
I'm writing a program that calculates input a user gives, simple numbers. 2, 4,
I'm writing a program where the user inputs names and then ages. The program
I'm writing a Cocoa OS X (Leopard 10.5+) end-user program that's using timestamps to
I am writing a basic program in Python that prompts the user to enter

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.