pythonwhile-loopfizzbuzz

The number % by 3 and 5 are reapiting


    print(i)
    if i % 3 == 0:
        print("cot")
    elif  i%5 == 0:
        print("cot")

the code will output number from 1 to 100 and if the number between 1 and 100 is % by 3 or 5 it will be replace with cot,but if the number is cot the number will be put again,without the :cot


Solution

  • If i understand you correctly, what you are trying to do is to change the number to cot if it's divisible by 3 or 5.

    So if any of those restrictions is accomplish, you need to assign 'cot' to the variable.

    Like this:

    i = <some number>
    if i%3 == 0:
        i = "cot"
    elif i%5 == 0:
        i = "cot"
    print(i)