fork(9) download
  1. n=eval(input("Enter n: ")) # keep sub 20-ish max
  2. for i in range(0,(2**n)):# loop from 0 to (2^n)-1
  3. cursub="Current Subset Contains Elements: "
  4. for j in range(0,n):
  5. if((1<<j) & i >0): #Checking if jth bit in i is set
  6. cursub+=(str(j+1)+" ")
  7.  
  8. print (cursub)
  9. print ("All ", (2**n)," Subsets printed")
  10.  
Success #stdin #stdout 0.02s 8688KB
stdin
3
stdout
Enter n: Current Subset Contains Elements: 
Current Subset Contains Elements: 1 
Current Subset Contains Elements: 2 
Current Subset Contains Elements: 1 2 
Current Subset Contains Elements: 3 
Current Subset Contains Elements: 1 3 
Current Subset Contains Elements: 2 3 
Current Subset Contains Elements: 1 2 3 
All  8  Subsets printed