1、打印如下结果:
1*5=5
2*10=20
3*15=45
...
10*50=500
for i in range(1,11):
print(str(i)+'x'+str((i*5))+'='+str((i*i*5)))
方法二:
for a in range(1,11):
b=a*5;
print(a,"*",b,"=",a*b);
2、本金10000元存入银行,年利率是千分之三,每过1年,将本金和利息相加作为新的本金。计算5年后,获得的本金是多少?
money = 10000
for i in range(5):
sum_money = money + money * 0.003
print(num1)
3、计算1900年1月1日到今天(如:2019年12月20日)相距多少天。
sum = 0;
for year in range(1900,2019):
if (year%4==0 and year%100!=0) or (year%400==0):
sum = sum + 366;
else:
sum = sum + 365;
for month in range(1,9):
if month in [1,3,5,7,8,10,12]:
sum = sum + 31;
elif month in [4,6,9,11]:
sum = sum + 30;
else:
if (2019% 4 == 0 and 2019 % 100 != 0) or (2019 % 400 == 0):
sum = sum + 29;
else:
sum = sum + 28;
print(sum-1);
4、打印如下图案:
*
**
***
****
*****
for i in range(1,6):
print('*'*i)
5、打印如下图案:
*
***
*****
*******
*********
for i in range(1,11,2):
print('*'*i)
6、打印如下图案:
#####*
####***
###*****
##*******
#*********
for j in range(1,11,2):
for i in range(1,11-j,2):
print('#',end='')
print('*'*j)
7、打印如下图案:
*
***
*****
*******
*********
*******
*****
***
*
s = '*'
for i in range(1,10,2):
print((s*i).center(9))
for i in reversed(range(1,8,2)):
print((s*i).center(9))
8、打印99乘法表
for i in range(1,10):
for j in range(1,i+1):
print(str(j)+'x'+str(i)+'='+str(j*i),end=' ')
print()
9、定义一个List,任意输入10个数字保存到List,然后按从小到大排序。(冒泡排序)
list1 = []
for j in range(1,11):
num = input('请输入10个数字,已输入第{}个数'.format(j))
num = int(num)
list1.append(num)
len_sum = len(list1)
for x in range(len_num-1):
for y in range(len_num-1-x):
if list1[y]>list1[y+1]:
list1[y],list1[y+1]=list1[y+1],list1[y]
print(list1)