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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:17:55+00:00 2026-05-20T22:17:55+00:00

Using Python v2.x, I have 3 variables that I want to ask the user

  • 0

Using Python v2.x, I have 3 variables that I want to ask the user for, as below:

 def Main():

    chars = set('0123456789')

    while True:
       Class_A_Input = raw_input('Enter Class A tickets sold: ')
       Class_B_Input = raw_input('Enter Class B tickets sold: ')
       Class_C_Input = raw_input('Enter Class C tickets sold: ')

        if any((c in chars) for c in Class_A_Input):
            break
        else:
            print 'Wrong'

    total_profit((int(Class_A_Input)), (int(Class_B_Input)), (int(Class_C_Input)))

How can I check if the user input is a valid input. IE: I want only numerical data entered. I have done this once before using ‘chars = set(‘0123456789’) and the ‘WHILE’ functions, but cannot seem to get it to work for multiple inputs.

Thanks for any help.

EDIT: I have put the code in now as I have it. I moved the ‘int’ to the ‘total_profit’ variable. How can I check all inputs?

  • 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-20T22:17:55+00:00Added an answer on May 20, 2026 at 10:17 pm
    def getInt(msg):
        while True:
            try:
                return int(raw_input(msg))
            except ValueError:
                pass
    
    def total_profit(a, b, c):
        return 35.0*a + 25.0*b + 10.0*c
    
    def main():
        class_a = getInt('Enter Class A tickets sold: ')
        class_b = getInt('Enter Class B tickets sold: ')
        class_c = getInt('Enter Class C tickets sold: ')
    
        print("Total profit is ${0:0.2f}.".format(total_profit(class_a, class_b, class_c)))
    
    if __name__=="__main__":
        main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python logger set up, using python's logging module. I want to
I'm using python, and I want a function that takes a string containing a
I have a webpage that I read using Python and BeautifulSoup, say soup=BeautifulSoup(urllib2.urlopen(site)) .
i'm using python twisted and i have two separate servers working, one that recieves
I have an application written in Python 2.7 that reads user's file from the
I have a Python script that I want to use as a controller to
I came across a strange issue in Python when using global variables. I have
I just started using/learning Python and have some questions. I have a text file
I am new to selenium and I am using python but I have a
Does Python have a built-in, simple way of encoding/decoding strings using a password? Something

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.