#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019/3/11 8:20
# @Author : cunyu
# @Site : cunyu1943.github.io
# @File : 6-1.py
# @Software: PyCharm
# 简单输出整数
# https://pintia.cn/problem-sets/14/problems/733
def PrintN(N):
for i in range(1, N+1):
print(i)
if __name__ == '__main__':
number = int(input('输入一个正整数:'))
PrintN(number)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019/3/11 8:50
# @Author : cunyu
# @Site : cunyu1943.github.io
# @File : 6-2.py
# @Software: PyCharm
import math
# 多项式求值
# https://pintia.cn/problem-sets/14/problems/734
def f(n, a, x):
result = 0
for i in range(n+1):
tmp = a[i] * pow(x, n)
result += tmp
return result
if __name__ == '__main__':
n = int(input('输入n\n'))
x = float(input('输入x\n'))
a = []
for i in range(n+1):
a.append(float(input('输入a[{}]\n'.format(i))))
print(f(n, a, x))
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019/3/11 9:19
# @Author : cunyu
# @Site : cunyu1943.github.io
# @File : 6-3.py
# @Software: PyCharm
# 简单求和
# https://pintia.cn/problem-sets/14/problems/735
def Sum(List, N):
result = 0
for i in List:
result += i
return result
if __name__ == '__main__':
List = []
N = int(input('输入元素个数\n'))
for i in range(N):
List.append(int(input('输入List[{}]\n'.format(i))))
print('最后结果是:{} '.format(Sum(List, N)))
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019/3/11 19:58
# @Author : cunyu
# @Site : cunyu1943.github.io
# @File : 6-4.py
# @Software: PyCharm
# 求自定类型元素平均值
# https://pintia.cn/problem-sets/14/problems/736
def Average(S, N):
total = 0
for i in S:
total += i
avg = total / N
return avg
if __name__ == '__main__':
N = int(input('输入元素个数:\n'))
S = []
for i in range(N):
S.append(float(input('输入S[{}]: '.format(i))))
print('均值为: %.2f\n' % (Average(S, N)))
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019/3/11 20:13
# @Author : cunyu
# @Site : cunyu1943.github.io
# @File : 6-5.py
# @Software: PyCharm
# 求自定类型元素的最大值
# https://pintia.cn/problem-sets/14/problems/737
def Max(S, N):
tmp = S[0]
for i in range(1, N):
if tmp < S[i]:
tmp = S[i]
return tmp
# return max(S)
if __name__ == '__main__':
N = int(input('输入元素个数:\n'))
S = []
for i in range(N):
S.append(float(input('输入S[{}]: '.format(i))))
print('Max is : %.2f' % Max(S, N))
建议关注 公众号,文章会优先发布在此处,此外还有 大量精品资源 等着你。
小编收集资源也很辛苦,大家看完文章后,记得顺手点个在看!或者赞赏个鸡腿儿也是很满足鸭!比心 ♥