-3
  x = Flase
  while !x :
     a = 0
     print(a)
     a++
     pass
     if a == 10:
       x = True
    else:
       continue  

I get an error at "a++". I a using visual studio 2013 community and it gives me a red underline after "a++" and just before "pass"

  • 3
    possible duplicate of [Python integer incrementing with ++](http://stackoverflow.com/questions/2632677/python-integer-incrementing-with) – Matthew Read Jul 21 '15 at 04:44
  • Please check your spelling before asking questions. a++ is an invalid python syntax. Use a += 1 instead. !x is an invalid python syntax as well. Use not x instead. Remember python is not Java or C#. – Eddie Jul 21 '15 at 04:55
  • simply use a += 1 – ivan73 Feb 26 '17 at 07:31

2 Answers2

2

Python does not support ++. you can do this

     a = a + 1 
0xtvarun
  • 698
  • 6
  • 18
0

There is no syntax like ++ or -- in Python, but you can do += 1 and -= 1.

And there are some logical error in your program

x = False
a = 0  # a should be initialized here. If it is initialized in loop it will be a never-ending loop
while not x :

   print(a)
   a+=1
   if a == 10:
     x = True
   else:
     continue

Notes:

  1. check the spelling on False you have written it wrong

  2. there is no need for pass

  3. instead of using ! you should use not in Python

A simpler and more pythonic way is to use for and range:

for a in range(10):
    print(a)
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
The6thSense
  • 8,103
  • 8
  • 31
  • 65