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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:27:37+00:00 2026-06-17T23:27:37+00:00

I am new to doing simple math using python, so sorry if this is

  • 0

I am new to doing simple math using python, so sorry if this is a silly question.

I have 8 variables that are all set to integers and these integers are used when performing a simple calculation.

a = 0
b = 17
c = 152
d = 1
e = 133
f = 19
g = 20
h = 0

answer = ( ( ( a / f ) + b + c ) - ( g + ( h / f ) ) ) / ( d / f )

print answer

When I run this code, I get the error, ZeroDivisionError: integer division or modulo by zero.

I have read about this error and all documentation points towards my divisor being zero, but if I print this with the numbers as strings in place of the variables, I get:

( ( ( 0 / 19 ) + 17 + 152 ) - ( 20 + ( 0 / 19 ) ) ) / ( 1 / 19 )

Nowhere in this statement is the divisor zero.

Please let me know how I need to change my expression in order to get the answer 2831. Note that I can change the type of the variables to a float or other. Thank you for your help!

  • 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-17T23:27:38+00:00Added an answer on June 17, 2026 at 11:27 pm

    Probably you are using Python 2.x, where x / y is an integer division.

    So, in the below code: –

    ( 20 + ( 0 / 19 ) ) ) / ( 1 / 19 )
    

    1 / 19 is an integer division, which results in 0. So the expression is essentially same as: –

    ( 20 + ( 0 / 19 ) ) ) / 0
    

    Now you see where the error comes from.


    You can add following import in you python code, to enforce floating-point division: –

    from __future__ import division
    

    Or you could cast one of the integers to a float, using either float() or just by adding .0 to the initial value.

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

Sidebar

Related Questions

I am doing simple formatting for an email with StringBuilder and have code that
I imagine that this is a simple question, but I'm getting some strange results
The new Basecamp is doing it, as it can be seen in this link
I'm doing some tests with new features of CSS3, but this combination only works
I'm doing simple tests on all files in directory. But from some reason, sometimes,
Am doing a simple android application.In that I am deleting an element from array
I'm doing a project that spawn some hundreds of threads. All these threads are
I was doing simple things with hibernate, as I have to learn it for
I've overloaded the global operator new/delete/new[]/delete[] but simple tests show that while my versions
I have a jQuery UI which is doing simple autocomplete function. Autocomplete is coming

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.