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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:29:58+00:00 2026-05-16T16:29:58+00:00

I am facing the problem while dividing my max_sum = 14 total_no=4 so when

  • 0

I am facing the problem while dividing

my max_sum = 14
total_no=4  

so when i do

print "x :", (total_sum/total_no)

, I get 3 and not 3.5

I tried many ways for printing but failed, can somebody let me know what way I get in 3.5 format?

Thank you

  • 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-16T16:29:59+00:00Added an answer on May 16, 2026 at 4:29 pm

    In Python 2.x, dividing two integers by default dives you another integer. This is often confusing, and has been fixed in Python 3.x. You can bypass it by casting one of the numbers to a float, which will automatically cast the other:

    float( 14 ) / 4 == 3.5

    The relevant PEP is number 238:

    The current division (/) operator has
    an ambiguous meaning for
    numerical arguments: it returns the floor of the mathematical
    result of division if the arguments are ints or longs, but it
    returns a reasonable approximation of the division result if the
    arguments are floats or complex. This makes expressions expecting
    float or complex results error-prone when integers are not
    expected but possible as inputs.

    It was not changed in Python 2.x because of severe backwards-compatibility issues, but was one of the major changes in Python 3.x. You can force the new division with the line

    from __future__ import division
    

    at the top of your Python script. This is a __future__-import — it is used to force syntax changes that otherwise might break your script. There are many other __future__ imports; they are often a good idea to use in preparation for a move to Python 3.x.

    Note that the // operator always means integer division; if you really want this behaviour, you should use it in preference to /. Remember, “explicit is better than implicit”!

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

Sidebar

Related Questions

I am trying to hide an array of elements but facing problem while writing
I am facing problem while setting focus in EdiText. Below is my EditText property.
I am facing problem while generating CAB file. I want to customize the INF
i am using mvc 3 code first. facing problem while passing data form SecurityAttribute
I am facing a problem while creating a static cursor in DB2. This is
I'm facing a problem while deleting a record that is referenced by another table.
I am facing a problem while disabling the command button after one click. I
I am facing the problem while inserting data this way. How to insert data
I am new to Android development and facing a problem while using AndEngine. I
I'm currently facing a weird problem while executing a command from my bash script.

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.