79.0k views
0 votes
For this question you should write code using the tools you learned so far. The code will find all the integers in the interval from 1 to 12000 that are divisible by both 3 and 14. Print all the numbers that satisfy this criterion and also print a statement saying how many such number exist in the range. Hint: The "modulo" operator is denoted by a percent sign % in Python. It returns the remainder when two integers are divided. For example, 5%2 (read: "5 mod 2") returns a value of 1, because 5 divided by 2 is 2 with the remainder 1. The result of a modulo x%d is always between 0 and d-1. Use the modulo operator to help determine if one integer is divisible by another. Second Hint: Remember the logical operators and, or and not are available in Python.

1 Answer

2 votes

Answer:

The code in Python 3.7 than answers this question is given below:

def main():

cont = 0

for i in range(1, 12001):

if i%3 == 0 and i%14 == 0:

print(i)

cont += 1

print("{} numbers are divisible by 3 and 14".format(cont))

if __name__== "__main__":

main()

Step-by-step explanation:

#Create the main function, inside this is our logic to solve the problem

def main():

#Define a cont variable that storage the amount of numbers that satisfy the condition given

cont = 0

#For loop between 1 and 12000

for i in range(1, 12001):

#Use the mod function to know if is divisible by 3 and by 14

if i%3 == 0 and i%14 == 0:

#Print the number that satisfy the condition

print(i)

#Refresh the cont variable if the condition is satisfied

cont += 1

#Print the output

print("{} numbers are divisible by 3 and 14".format(cont))

if __name__== "__main__":

#Run the main function

main()

User AmbroseChapel
by
4.8k points