On 11/10/2016 22:26, Lawrence D’Oliveiro wrote:
On Wednesday, October 12, 2016 at 6:58:46 AM UTC+13, dhawan...@gmail.com wrote:
Only first loop is executing not the second one?
n=6
x=1
while x<=n:
print("*"*x)
x+=1
print('n=', n)
print('x=', x)
while n>=x:
n=n-1
print("*"* n)
*
**
***
****
*****
******
n= 6
x= 7
Moral: always use debug print statements to figure out what is going on.
'else' can be used here:
n=6
x=1
while x<=n:
print "*"*x
x+=1
while n>=x:
n=n-1
print "*"* n
else:
print ("2nd loop exit n=",n,"x=",x)
--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list