目录
3.求出1000以内的所有完数,如6=1+2+3除了它自身以外的因子之和等于它本身叫完数。
4.用循环语句求1+22+333+4444+55555的和。
5.求出2000-2100的所有闰年,条件是四年一闰;百年不闰,四百年再闰。
1.从键盘输入三个同学的成绩,然后找出最高分。
print("依次输入三个学生的成绩")
x = int(input())
y = int(input())
z = int(input())
if x > y and x > z :
print(x)
elif y > x and y > z:
print(y)
elif z > x and z > y:
print(z)
else:print("成绩一样")
看到的一个简便方法直接使用max内置函数
print("依次输入三个学生的成绩")
x = int(input())
y = int(input())
z = int(input())
d = max(x,y,z)
print(d)
max = 0
for x in rang(3):
a = int(input("请输入一个学生的成绩"))
if ( max < a ):
max = a
print(max)
运行结果:
依次输入三个学生的成绩
98
99
100
100
2.输入三个同学的成绩,然后由大到小排序。
print("输入三个不一样的数字")
x = int(input())
y = int(input())
z = int(input())
if x != y and x != z and z != y:
if x > y :
if y > z :
print(x,y,z)
elif z > y and z > x :
print(z,x,y)
else:print(x,z,y)
elif x < y :
if x > z :
print(y,x,z)
elif y < z :
print(z,y,x)
else : print("有数字一样从新输入")
简便方法:
print("输入三个不一样的数字")
x = int(input())
y = int(input())
z = int(input())
d = max(x,y,z)
e = []
e.append(x)
e.append(y)
e.append(z)
e.sort(reverse=True)
print(e)
运行结果&