+ 2
How do i make this more concise?
basic math function. takes 2 integers as a range and returns a Boolean statement for each integer in that range based on a division statment of a 3rd input integer having a 0 remainder value. https://code.sololearn.com/c52jl0i80LM4/?ref=app edit: with thanks to visph for cleaning up the junk I posted. The link now points to the updated version, and possibly later updates as well.
1 Answer
+ 8
# To be more concise:
# - don't use new variables to get the range
# - test if per==0 instead use try/finally (all the most if you doesn't use 'catch' statement
# - don't need to use str(div) as 'div' is already a String type ^^
# - your 'percentfinder' function doesn't return any value, so you don't need to call it with an assignment to a 'pfind' variable (and anyway, you should 'print(pfind)' to display it's value :P)
def percentfinder(rg,rge,per):
if per==0:
print("Cannot divide by 0.")
return
for i in range(rg,rge+1):
if int(i)%per==0:
div=""
else:
div=" not"
print (str(i)+" is"+div+" divisable by "+str(per))
ab=int(input())
bc=int(input())
cd=int(input())
percentfinder(ab,bc,cd)