g Write a program that prompts the user to enter two integers. The program outputs how many numbers are multiples of 3 and how many numbers are multiples of 5 between the two integers (inclusive).

Respuesta :

Answer:

number1=int(input("Enter first smallest integer number: "))#take the first integer from the user.

number2=int(input("Enter the second greatest integer number: "))#Take th esecond integer from the user.

if(number1>number2):#if condition

   print("The number is wrong, please try again")

else:

   multiple_of_3=0 #take a variable to count the multiple of 3.

   multiple_of_5=0 #take a variable to count the multiple of 5.

   while(number1<=number2):#while loop.

       if(number1%3==0):#if condition to count the multiple of 3.

           multiple_of_3=multiple_of_3+1#operation to count the multiple of 3.

       if(number1%5==0):#if condition to count the multiple of 3.

           multiple_of_5=multiple_of_5+1#operation to count the multiple of 3.

       number1=number1+1

   print("There are "+str(multiple_of_3)+" number are multiple of 3 and "+str(multiple_of_5)+" are multiple of 5")#print the count.

Output:

  • If the user gives the input 1 and 15, then it will print 5 for 3 multiple and 3 for 5 multiple.
  • If the user gives the input as 7 and 15, then it will print 3 for a multiple of 3 and 2 for a multiple of 5.

Explanation:

  • The above code is in python language, which is used to count the number of 3 multiple and 5 multiple.
  • There is a while loop that runs from the smallest number to greatest number and the check the number that it is a multiple of 5 and 3 or not by the help of if condition.
  • If it is multiple of 3, then multiple_of_3 variable is incremented by 1 and if it is a multiple of 5 then the multiple_of_5 is incremented by 1.