Skip to content

Instantly share code, notes, and snippets.

@Logic2apply
Last active May 2, 2021 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Logic2apply/eba226789d77e733767db04ef768d9b2 to your computer and use it in GitHub Desktop.
Save Logic2apply/eba226789d77e733767db04ef768d9b2 to your computer and use it in GitHub Desktop.
Divide the Apples - Factor Generator

Divide the Apples

Problem Statement-

Harry Potter has got the “n” number of apples. Harry has some students among whom he wants to distribute the apples. These “n” number of apples is provided to harry by his friends, and he can request for few more or few less apples.

You need to print whether a number is in range mn to mx, is a divisor of “n” or not.

Input-

Take input n, min, and max from the user.

Output-

Print whether the numbers between mn and mx are divisor of “n” or not. If mn=mx, show that this is not a range, and mn is equal to mx. Show the result for that number.

Example-

If n is 20 and mn=2 and mx=5

2 is a divisor of20

3 is not a divisor of 20

...

5 is a divisor of 20

# Divide the Apples
try:
n = int(input("\nEnter the number of apples you got\n: "))
mn = int(input("\nEnter the Minimim number\n: "))
mx = int(input("\nEnter the Maximum number\n: "))
except Exception as e:
print("Invalid input! Only integer allowded")
exit()
def checkdiv():
if n%mn==0:
print(f"{mn} is a divisor {n}")
else:
# print(f"{mn} is not a divisor of {n}")
pass
if mn==0 or mx==0 or n==0:
print("Can't except 0 for apple-min-max!!\n")
exit()
elif mx>mn:
print("Maximum n umber should be greater than or equal to minimum number!!")
exit()
else:
if mn==mx:
checkdiv()
else:
while mn<=mx:
checkdiv()
mn += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment