ubuntuuser771
ubuntuuser771

Reputation: 19

Unable to get division to work in my program

I'm trying to get my python program to make a division table and my terminal keeps giving me this error when I try to run it:

File divisiontable.py, Enter a Number:4 Enter a start:0 Enter an end:100 Traceback (most recent call last): File divisiontable.py, line 24, in w = tablep() File divisiontable.py, line 10, in tablep s = str(n) + "/" + str(i) + "= " + str(n//i) ZeroDivisionError: integer division or modulo by zero

This is the program:

def tablep():
    n=int(input("Enter a Number:"))
    start=int(input("Enter a start:"))
    end=int(input("Enter an end:"))

    file=open("div-table.txt","a")

    if start<end:
        for i in range(start,end+1):
            s = str(n) + "/" + str(i) + "=  " + str(n//i)
            file.write(s)
            file.write("\n")
            print(n,"/",i,"=",n//i)

    elif start>end:
        for i in range(start,end,-1):
            s = str(n) + "/" + str(i) + "=  " + str(n // i)
            file.write(s)
            file.write("\n")
            print(n, "/", i, "=", n // i)

    file.close()

w = tablep()

I don't have any idea what this error means. I'm using python version 2.7.18 and python version 3.8.5. How would I go about getting this program to work? Thanks for your time.

Upvotes: 0

Views: 156

Answers (1)

nissim abehcera
nissim abehcera

Reputation: 831

Impossible to divide by 0 , start must be not equals to 0

Upvotes: 2

Related Questions