如何用 for循环语句以#打印一个正弦图像
Modify the following program to ask the user for the number of steps (instead of using 31 fixed steps).
import math
sin = math.sin
pi = math.pi
for i in range(31):
x = float(i) / 30.0 * 2 * pi
print( sin(x) )
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import math
def pr(i):
#输出##
if i>0:
i=i*2
elif i<0:
i*=-1;
str=""
while i>0:
str+="#";
i-=1;
print str;
sin = math.sin
pi = math.pi
for i in range(31):
x = float(i) / 30.0 * 2 * pi
y=sin(x)*20
pr(y)
上面的哪个代码,if判断多此一举。。
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import math
def pr(i):
#输出##
str=""
while i>0:
str+="#";
i-=1;
print str;
sin = math.sin
pi = math.pi
for i in range(31):
x = float(i) / 30.0 * 2 * pi
y=sin(x)*20
pr(y)