0
q = int(input("How many numbers do you need to check? "))
dt = 0
ndt = 0

for i in range(q):
    w = int(input("Enter number: "))
if w % 3 == 0:
    print("{} is divisible by 3.".format(w))
    dt = dt + 1
else:
    print("{} is not divisible by 3.".format(w))
    ndt = ndt + 1
print("You entered {} number(s) that are divisible by 3".format(dt))
print("You entered {} number(s) that are not divisible by 3".format(ndt))

I'd like my ask the user to "Enter number" and then after it'll subsequently answer if it divisible by three or not.

Ex:

"Enter number: 6"
"6 is divisible by 3"
"Enter number: 9"
"9 is divisible by 3"
"Enter number: 11"
"11 is not divisible by 3"

"You entered 2 number(s) that are divisible by 3"
"You entered 1 number(s) that are not divisible by 3"

I truly haven't really tried anything.

1
  • Indent your if/else block so that it is in the for loop. Right now you are only running it after the for loop finishes. Commented Oct 26, 2022 at 15:21

1 Answer 1

1

I think it's just your tabbing that needs to be changed. To get your if statement inside the loop it needs to be tabbed to the correct position.

q = int(input("How many numbers do you need to check? "))
dt = 0
ndt = 0

for i in range(q):
    w = int(input("Enter number: "))
    if w % 3 == 0:
        print("{} is divisible by 3.".format(w))
        dt = dt + 1
    else:
        print("{} is not divisible by 3.".format(w))
        ndt = ndt + 1
print("You entered {} number(s) that are divisible by 3".format(dt))
print("You entered {} number(s) that are not divisible by 3".format(ndt))
Sign up to request clarification or add additional context in comments.

2 Comments

^ Thanks, it was the tabbing that was the issue!
No worries! If the answer solved your problem then marking it as an accepted answer is appreciated @ShaneHarris

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.