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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:08:53+00:00 2026-05-30T22:08:53+00:00

I’m a programming newbie having difficulty with Python multiplication. I have code like this:

  • 0

I’m a programming newbie having difficulty with Python multiplication. I have code like this:

def getPriceDiscount():
    price = int(input())
    if price > 3000:
        priceDiscount = price * 0.6
        return priceDiscount
    else:
        return price

But when I execute it and type an input which is a decimal number like 87.94, I get the following error:

ValueError: invalid literal for int() with base 10: '87.94'

Isn’t the int() method able to convert the string ‘87.94’ into a number allowing me to multiply it by 0.6? What should I do to perform that conversion?

I’m using Python 3.2.2.

  • 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-30T22:08:54+00:00Added an answer on May 30, 2026 at 10:08 pm

    An int (short for “integer”) is a whole number. A float (short for “floating-point number”) is a number with a decimal point.

    int() returns an int created from its input argument. You can use it to convert a string like "15" into the int 15, or a float like 12.059 into the int 12.

    float() returns a float created from its input argument. You can use it to convert a string like "10.5" into the float 10.5, or even an int like 12 into the float 12.0.

    If you want to force price to be an integer, but you want to accept a floating point number as typed input, you need to make the input a float first, then convert it with int():

    price = int(float(input())
    

    Note that if you multiply an int by a float such as your discount factor, the result will be a float.

    Also note that my example above doesn’t round the number — it just truncates the stuff after the decimal point. For example, if the input is "0.6" then price will end up being 0. Not what you want? Then you’ll need to use the round() function on the float first.

    price = int(round(float(input()))
    

    If you intended to use floating point calculations (which makes sense if we’re talking about a commodity price), then don’t perform the int conversion. Just use float. You may still want to do some rounding. If you want to round to 2 decimal places, you can call round with the second argument as 2:

    price = round(float(input()),2)
    

    Finally, you might want to look into Python’s decimal module, since there are limitations when using floating point numbers. See here for more information: http://docs.python.org/tutorial/floatingpoint.html

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have this code to decode numeric html entities to the UTF8 equivalent character.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't

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.