登录后查看本帖详细内容!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
5.17: count=0 for i inrange(ord('~')-ord('!')): count+=1 print(chr(i),end='') if count % 10 ==0: print() 5.18: number=eval(input('enter oneinteger:')) i=2 for i inrange(i,number+1): while number % i ==0: number = number // i print(i,end=',') else: i+=1 5.19: num=eval(input('enter an integer(0~15):')) for i in range(1,num+1): for j in range(num-i,0,-1): print(' ',end='') for j in range(i,1,-1): print(j,end='') for j in range(1,i+1): print(j,end='') print() 5.20: print('模式A') num=6 for i in range(1,num+1): for j in range(1,i+1): print(j,end='') print() print('模式B') for i in range(1,7): num=6 for j in range(1,num+2-i): print(j,end='') num-=1 print() print('模式C') num=6 for i in range(1,num+1): for j in range(num-i,0,-1): print(' ',end='') for j in range(i,0,-1): print(j,end='') print() print('模式D') for i in range(1,7): num=6 for j in range(1,i): print(' ',end=' ') for j in range(1,num+2-i): print(j,end=' ') print() 5.21: num=eval(input('enter an integer(2**n数字金字塔):')) for i in range(1,num+1): for j in range(num-i,0,-1): print(format(' ','3s'),end=' ') for j in range(1,i): print(format(2**(j-1),'3d'),end=' ') for j in range(i,0,-1): print(format(2**(j-1),'3d'),end=' ') print() 5.22: number_of_primes_per_line=8 count=0 number=2 while count <=1000: isprime=True divisor=2 while divisor <= number/2: if number % divisor ==0: isprime=False break divisor+=1 if isprime: count+=1 print(format(number,'5d'),end='') if count % number_of_primes_per_line==0: print() number+=1
|