Python3.4 while循环增加

2024-10-05 11:16:09 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我在“a++”时出错。我使用的是visualstudio2013社区,它在“a++”之后和“pass”之前给我一条红色下划线


Tags: trueifpass社区elseprint红色continue
2条回答

Python中没有++这样的语法,但是您可以执行+= 1和{}。在

你的程序有一些逻辑错误

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

注意事项:

  1. 检查False上的拼写是否有误

  2. 不需要pass

  3. 您应该在Python中使用not,而不是使用!

使用forrange:

^{pr2}$

Python不支持++。你能做到的

     a = a + 1 

相关问题 更多 >

    热门问题