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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:46:06+00:00 2026-05-17T23:46:06+00:00

a = raw_input(‘How much is 1 share in that company? ‘) while not a.isdigit():

  • 0
a = raw_input('How much is 1 share in that company? ')

while not a.isdigit():
    print("You need to write a number!\n")
    a = raw_input('How much is 1 share in that company? ')

This only works if the user enters an integer, but I want it to work even if they enter a float, but not when they enter a string.

So the user should be able to enter both 9 and 9.2, but not abc.

How should I do it?

  • 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-17T23:46:06+00:00Added an answer on May 17, 2026 at 11:46 pm

    Use regular expressions.

    import re
    
    p = re.compile('\d+(\.\d+)?')
    
    a = raw_input('How much is 1 share in that company? ')
    
    while p.match(a) == None:
        print "You need to write a number!\n"
        a = raw_input('How much is 1 share in that company? ')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This happens if a prompt is written using sys.stdout.write or print instead of raw_input
Consider this code: >>> num = int(raw_input('Enter the number > ')) If the user
I have following script: #!/usr/bin/python while True: x = raw_input() print x[::-1] I am
I have this python program that adds strings to integers: a = raw_input("Enter a:
I'm trying something like this Output.py print Hello Input.py greeting = raw_input(Give me the
I'm new to python, I'm using v2.7 #Filename:ReverseNumber.py data=int(raw_input(Enter any number: )) print Reverse
I have the following code: num = int(raw_input(input number: )) print \b * 20
Here's my code: sentenceToTranslate = raw_input(Please write in the sentence you want to translate:
Is there a C function that does the same as raw_input in Python? #in
I make this program :: #include<stdio.h> char *raw_input(char *msg); main() { char *s; *s

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.