mercredi 23 septembre 2020

print all the numbers in a range that are divisible by 4 or 5, but not both

I'm trying to print all the numbers from 100 to 200, ten per line, that are divisible by 4 or 5, but not both. The numbers in a printed line are separated by exactly one space. Example of what I'm trying to achieve is:

104 105 108 110 112 115 116 124 125 128 
130 132 135 136 144 145 148 150 152 155 
156 164 165 168 170 172 175 176 184 185 
188 190 192 195 196

I have tried this:

i=100
a=100
while i<=200:
    if ((a%3 and a%5)==0) :
        a=a+1
    elif a/3 ==0 and a/5 != 0:
        print(a)
        a=a+1
    else:
        print(a," ")
        a=a+1
    i=i+1

I can get it to print all the numbers from 100-200 and not the ones divisible by 4 and 5 but I cant quite get it to print numbers divisible by 4 or 5 but not 4 and 5. also getting them to print 10 per line has been a tricky

Appreciate any help or being put in the right direction

Aucun commentaire:

Enregistrer un commentaire