git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Nested Loop Code Help


Hello people, I have written the code below which works fine, but it has one small problem. Instead of printing one (x) on the first line, it prints two.
I have tried everything in my knowledge, but cannot fix the problem.
Thanks for any help in advance.  


for x in range ( 0, 10):	 	       	  	  	  	    	   	
  stars = 'x'	 	       	  	  	  	    	   	
  count = 0	 	       	  	  	  	    	   	
	 	       	  	  	  	    	   	
while count < x:	 	       	  	  	  	    	   	
  stars = stars + 'x'	 	       	  	  	  	    	   	
  count = count + 1	 	       	  	  	  	    	   	
  print (stars)



Output I am trying to get                         Output I am getting
x                                                 xx
xx                                                xxx
xxx                                               xxxx
xxxx                                              xxxxx
xxxxx                                             xxxxxx
xxxxxx                                            xxxxxxx
xxxxxxx                                           xxxxxxxx
xxxxxxxx                                          xxxxxxxxx
xxxxxxxxx                                         xxxxxxxxxx
xxxxxxxxxx