学习Python应该勤于练习,而Pythontip是一个很好的在线编程平台,其中的例题也较为经典。但是,对于新手,苦于没有通俗易懂,简短精炼答案,而被迫放弃。现提供1-10参考答案。
1.
print a + b
2.
print sorted(L)
3.
print a[::-1]
4.
L = []
for key in a:
key = str(key)
L.append(key)
print ‘,’.join(sorted(L))
5.
print a[::2]
6.
def judge(x):
if x == 1:
return 0
i = 2
while i < x:
if x % i == 0:
return 0
i = i + 1
return 1
L = []
for num in range(1,101):
if judge(num) == 1:
num = str(num)
L.append(num)
print ’ '.join(L)
7.
s = a * b
c = (a + b) * 2
print s,c
8.
L = sorted(L)
l = len(L)
if l % 2 == 0:
x = (L[l/2-1] + L[l/2]) / 2.0
else:
x = L[l/2]
print x
9.
if a > b:
a,b = b,a
while b % a != 0:
b,a = a,b%a
print a
10.
mul = a * b
if a > b:
a,b = b,a
while b % a != 0:
b,a = a,b%a
print mul/a
此为个人编写,如有异议,欢迎讨论!
Pythontip例题解答
最新推荐文章于 2025-03-24 15:09:07 发布