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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:36:01+00:00 2026-06-15T02:36:01+00:00

I have some functions calling for user input, sometimes string, int or whatever. so

  • 0

I have some functions calling for user input, sometimes string, int or whatever. so i noticed that if ENTER is pressed with NO INPUT i get an error. SO i did some research and i think i found that EVAL function may be what I’m looking for, but then again i read about its dangers.

SO here are my questions:

  1. How can i check/force user input? EX: repeating the input string or maybe even warning user that he didn’t enter anything?

  2. how do i check for the correct type of input (int, float, string, etc) against whatever the user types without having my scripts returning errors?

I appreciate your feedback,

Cheers

  • 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-15T02:36:02+00:00Added an answer on June 15, 2026 at 2:36 am

    For question 1: enter pressed when prompted for input results in an empty string returned (are you using input() in your scripts?). Apparently empty string is not a valid input for your functions. For all I know, whatever you enter as the input, you end up with a string returned by input(). To check if a string is empty and repeat the prompt, you may try:

    while True:
        answer = input('Enter something: ')
        if answer: break
    

    And for question 2: for checking the type of argument provided, generally the Pythonic way is to handle it with try/except and not check explicitly for each valid/non-valid type. Also, in this scenario you have to do explicit manual conversion from string, so you only check the contents of the string, not deal with other types (at least not yet). Because of than, you might be interested in string methods or re (regular expressions) module for checking if some particular substring is present (or not).

    re module for python3.3 and
    string methods for python3.3
    For other versions of python, just select an appropriate value in the menu in the top of the page.

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

Sidebar

Related Questions

I have some functions that I am calling and they take some time (milliseconds),
I have some functions that use opengl to draw lines on the screen (health
I have the following code: Some functions: A::A(int i_a) {cout<<int Ctor\n;} //conversion constructor void
I have some code in a couple of different functions that looks something like
I have some setup code in my functions.php file that sets permalinks and adds
I have made some helper functions that run a simulation using a lot of
I have a web app that stores some objects in the user session so
i have some functions(charfreq,wordfreq,charcount,wordcount,parerror) and i want to use it in dataStructure with the
I have some concerns related to the fact of testing some functions containing the
In the process of changing some code, I have spilt some functions into multiple

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.