按照你的要求用字符串类型编写的杨辉三角的Python程序如下
def printYangHui(n):
for i in range(1,n+1):
if i==1:
s="1"
if i==2:
s="1,1"
if i>2:
s1=""
begin=0;
for j in range(0,(i-3)+1):
begin1=s.find(",",begin)
begin2=s.find(",",begin1+1)
if begin2==-1:
begin2=begin1+2
s1=s1+str(int(s[begin:begin1])+int(s[begin1+1:begin2]))+","
begin=begin2-(begin2-begin1-1)
s="1,"+s1+"1"
print(s)
n=int(input())
printYangHui(n)
源代码如下(注意源代码的缩进)