Home > Mobile >  in this i could not understand about 3000 in range please answer
in this i could not understand about 3000 in range please answer

Time:02-27

num_1 = int(input("Enter The Number : ")) print("2") print("3") print("5") print("7") for n in range (3000,num_1 1): if n%2 != 0 and n%3 != 0 and n%5 != 0 and n%7 != 0 : print(n)

CodePudding user response:

This python range() function returns a sequence of numbers that are not multiple of 2(n%2 !=0), not multiple of 3(n%3 !=0), not multiple of 5(n%5 !=0), not multiple of 7(n%7 !=0) starting from '3000', and stops at the input value for num_1 before a specified number.

Note that if num_1 is less than the starting value - 3000, it result to having null values

CodePudding user response:

I gather this is what your program looks like when formatted (correct me if I am wrong/format the code in the question so it is clear):

num_1 = int(input("Enter The Number : ")) 
print("2") 
print("3") 
print("5")
print("7")
for n in range(3000,num_1 1): 
  if n%2 != 0 and n%3 != 0 and n%5 != 0 and n%7 != 0 : 
    print(n)

When we go through the program line by line we notice a few things:

  • You are taking in a user input and storing it in num_1.
  • After printing some numbers, you have a for loop that ranges in values from 3000 to num_1 1. If num_1 1 is less than 3000, this range will be 0 and nothing further will be printed. On the other hand, if num_1 1 is greater than 3000, numbers that are not divisible by 2, 3, 5 and 7 will print out. That is what the modulus operations in the conditional statement are filtering for. This would be: 3001, 3007, 3011, 3013, 3019, 3023, 3029, etc. depending on what number was inputted.

If you are wondering why the range(3000,num_1 1) begins at 3000, I don't know either. That is where you will have to provide some more context of the program, what you're trying to achieve, and what you expect.

  • Related