a=b=c=0
for i in range(1,21):
print("Enter two nos")
a=int(input("enter first no:"))
b=int(input("enter second no:"))
if b==0:
print("division by zero error! aborting")
else:
c=a//b
print("quotient=", c)
else:
print("program over")
what does this program mean, what does this i in range is written,
it doesn't make sense and also is the logic ok? please i dont want useless answer, so please help me
thank you
Answers
This program let's user enter 2 numbers for division 20 times and displays the quotient after performing floor division.
It claims to abort the program if the dividend is 0, but doesn't actually abort. To actually abort from the loop, the break keyword is to be used after displaying abort on the screen.
The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number.
So i in this case gets incremented each time the loop runs starting from 1 & ending at 21, (but not including 21). In this particular case as the value of i is not used, it could be replaced with _
The else in the end makes no sense. Remove it & it will display program over after either the loop has run for 20 times or it was aborted early.