python - limiting characters printed for loop -



python - limiting characters printed for loop -

it's pretty much "bizz buzz" thing, although want create print 10 words or numbers per line, , in similar programme allow user input range, , set amount of words or numbers print per line

for in range (1,121): if i%3 == 0 , i%5 == 0 , i%7 == 0: print("zipzapzop") elif i%3 == 0 , i%5 == 0: print("zipzap") elif i%3 == 0 , i%7 == 0: print("zipzop") elif i%3 == 0: print("zip") elif i%5 == 0: print("zap") elif i%7 == 0: print("zop") else: print(i)

output:

1 2 zip 4 zap zip zop 8 zip zap 11 zip 13 zop zipzap 16 17 zip 19 zap zipzop 22 23 zip zap 26 zip zop 29 zipzap 31 32 zip 34 zap zip 37 38 zip zap 41 zipzop 43 44 zipzap 46 47 zip zop zap zip 52 53 zip zap zop zip 58 59 zipzap 61 62 zipzop 64 zap zip 67 68 zip zap 71 zip 73 74 zipzap 76 zop zip 79 zap zip 82 83 zipzop zap 86 zip 88 89 zipzap zop 92 zip 94 zap zip 97 zop zip zap 101 zip 103 104 zipzapzop 106 107 zip 109 zap zip zop 113 zip zap 116 zip 118 zop zipzap

this output, want create print 10 numbers or words per line. i'm not sure how go this.

outside of if block need

# bump number count count += 1 # every 10 print new line if count % 10 == 0 print('')

then need disable newline printing out normally. how depends on version of python using. if on 2.7.x utilize

from __future__ import print_function

then alter prints

print('zipzap',end=' ')

python

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -