-2
sevens = range(7, 1000000, 7)

x = int(input("Please enter a positive number less than one million: "))

if x in sevens:
    print("{} is divisible by seven.".format(x))

My question is why do I get the following as output? Why 3510 as the starting number when the ranges begins with 7?

3510, 83517, 83524, 83531, 83538, 83545, 83552, 83559, 83566, 83573, 83580, 83587, 83594, 83601, 83608, 83615, 83622, 83629, 83636, 83643......

Does the error has to do something with the computer memory or is the problem in my IDE(Pycharm Jetbrains)?

Thank you!

PERSOD
  • 11
  • 3

2 Answers2

1

To test if a number is fully divisible by another number use the % (aka Modulo) operation that gives you the rest of said division:

x = int(input("Please enter a positive number less than one million: "))

if x%7 == 0:
    print("{} is divisible by seven.".format(x))
    print("It fits {} times.".format(x//7))
else:
    print("{} is not divisible by seven - theres a rest of {}.".format(x,x%7)) 

Further reading:

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
1

This is your IDE (Pycharm) problem. Update your IDE. I ran the same code and I have the output starting from 7,14,... and so on.

Shan Ali
  • 564
  • 4
  • 12