python系列print报错问题

问题一:

#!D:\mysoft\mypython\python
#coding=utf-8
print '你好,美丽中国!'

报错

:::::::::::::::::::::

  File "test1.py", line 3
    print '你好,美丽中国!'
                   ^
SyntaxError: Missing parentheses in call to 'print'

::::::::::::::::::::::

print要加()括号,因为print是函数了。

::::

PS注意:在python3系列以上,raw_input()不能用了,改为input()用法了!

::::

问题二:

#!D:\mysoft\mypython\python
#coding=utf-8
import time
import sys
colours = ["1","2","3","4","5","6","7","8","9","10","100"]
for i in range(len(colours)):
 time.sleep( .5 )
 sys.stdout.write("which colour do you like?:[% %s]colour complete!\r" %colours[i])
 sys.stdout.flush()
报错

:::::::::::::::::::::

Traceback (most recent call last):
  File "test2017.py", line 8, in <module>
    sys.stdout.write("which colour do you like?:[% %s]colour complete!\r" %colou
rs[i])
TypeError: not all arguments converted during string formatting

:::::::::::::::::::::

% %s 多写了,后面的%colour不够用了!

然后,完美的进度条可以了~

 

posted @ 2017-12-12 21:15  创业说  阅读(6497)  评论(0编辑  收藏  举报