Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 打印字符串时出现语法错误_Python 2.7 - Fatal编程技术网

Python 2.7 打印字符串时出现语法错误

Python 2.7 打印字符串时出现语法错误,python-2.7,Python 2.7,我想打印图案 hello! 10 8 6 4 2 我已经编写了以下代码 print "Hello!"; num=10; while(num>=2) print num; num-=2; 执行时,它在第1行显示语法错误。首先,不要在Python代码中使用分号。有两种方法可以做到这一点 1) 使用While循环- print "Hello!" num = 10 while num >= 2: print num num -= 2 2) 用于循环- pri

我想打印图案

hello!
10
8
6
4
2
我已经编写了以下代码

print "Hello!";
num=10;
while(num>=2)
   print num;
   num-=2;

执行时,它在第1行显示
语法错误。

首先,不要在Python代码中使用分号。有两种方法可以做到这一点

1) 使用While循环-

print "Hello!"
num = 10
while num >= 2:
    print num
    num -= 2
2) 用于循环-

print "Hello!"
for i in range(10, 1,-2):
    print i

while条件
while num>=2: