def slowPrint(): #print n times by going through list and printing if true for i in range(n+1): if nlist[i]==True: print(i) def fastPrint(i): #print faster by printing strings of several numbers output = "" for i in range(i-100, i): if nlist[i]==True: output += str(i)+", " print(output) n = input("enter input") #receive input nlist = [False]*(n+1) #generate list for i in range(n+1): #go through list if i%7 == 0: #if list index is divisible by 7 nlist[i]=True #change element to True if i==100 or 1==200 or i==300: #i%100==0: fastPrint(i) #slowPrint()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question