1、用以下代码替换 PythonApplication1.py 文件中的代码。 此代码变体展开了 make_dot_string,以便用户在调试器中检查其各个步骤。 它还将 for 循环放入 main 函数,并通过调用该函数显式运行该循环:
from math import cos, radians # Create a string with spaces proportional to a cosine of x in degrees def make_dot_string(x): rad = radians(x) # cos works with radians numspaces = int(20 * cos(radians(x)) + 20) # scale to 0-40 spaces st = ' ' * numspaces + 'o' # place 'o' after the spaces return st def main(): for i in range(0, 1800, 12): s = make_dot_string(i) print(s) main()
2、按 F5 或选择“调试”>“开始调试”菜单命令,检查代码是否正常运行。 此命令会在调试器中运行代码,但由于在程序运行时未执行任何操作来暂停程序,因此它只针对几次迭代输出波浪图案。 按任意键关闭输出窗口。
这篇文档对您是否有帮助?