Question: Using python 3 I am trying to write a code for writing the numbers 1 to 100 but when the number is divisible by 3
Using python 3 I am trying to write a code for writing the numbers 1 to 100 but when the number is divisible by 3 we write ping, when the number is divisible by 5 we write pong, and when the number is divisible by 3 and 5 we would write ping pong.
I have written a base code that works other than the fact that when the number is divisible by 3 and 5 it does not write pingpong only pong whe the number is divisible by both 3 and 5 what can I do to fix this?
import stdio
i = 1 while ( i <= 100 ): if i % 3 == 0 : stdio.writeln( "ping" )
elif i % 5 == 0 : stdio.writeln( "pong" )
elif i % 15 == 0 : stdio.writeln( "pingpong" )
elif i % 1 == 0 : stdio.writeln(i)
else: stdio.write(str(i) + " ")
i += 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
