大一pta编程题python答案_Python3实现PTA平台-基础编程题目集(1)

版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。

输出简单整数要求代码#!/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))结果

厘米换算英尺英寸要求代码结果

要求

代码

结果

要求

代码

结果

要求

代码

结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值