num = int(input("Enter a number >>>:")) a = num + 1 for i in range(1,a): if i == 1 or i == (a-1): print("#\t"*(a-1)) else: print("#"+(" \t" * (a-2))+"#\t")
num = int(input(">>>:")) for i in range(num,0,-1): print((num - i)*"#\t"+i*"#\t")
num = int(input(">>>")) for i in range(num): print("#\t"*num) print("\t")
2.打印1-100内所有奇数之和:
sum = 0 for i in range(1,101,2): sum += i else: print(sum)
sum = 0 i = 0 while sum <= 100: if sum % 2 != 0: i = sum + i sum += 1 else: print(i)
打印1-100内所有正整数之和:
sum = 0 i = 0 while sum <= 100: i = sum + i sum += 1 print(i)
几道基础知识练习题
原文地址:http://blog.51cto.com/limingyu/2124807
时间: 2024-10-10 09:18:24