23.7k views
5 votes
Write a program that will ask a user how many numbers they would like to check. Then, using a for loop, prompt the user for a number, and output if that number is divisible by 3 or not. Continue doing this as many times as the user indicated. Once the loop ends, output how many numbers entered were divisible by 3 and how many were not divisible by 3.

User SHiRKiT
by
8.6k points

1 Answer

3 votes

# Ask the user how many numbers they want to check

num_count = int(input("How many numbers would you like to check? "))

# Initialize variables to keep track of the count

divisible_count = 0

not_divisible_count = 0

# Use a for loop to prompt the user for a number and check if it is divisible by 3

for i in range(num_count):

num = int(input("Enter a number: "))

if num % 3 == 0:

print(num, "is divisible by 3")

divisible_count += 1

else:

print(num, "is not divisible by 3")

not_divisible_count += 1

# Output the count of numbers that were divisible by 3 and the count that were not

print(divisible_count, "numbers were divisible by 3")

print(not_divisible_count, "numbers were not divisible by 3")

User ChviLadislav
by
7.7k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.