PTA Python第二周题解
2021/10/17 17:10:07
本文主要是介绍PTA Python第二周题解,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
7-1 产生每位数字相同的n位数 (30 分)
a,b = map(int, input().split(",")) for i in range(1, b+1): print(a, end="")
7-2 输出10个不重复的英文字母 (50 分)
s = input() count = 0 data = [] for i in range(len(s)): if s[i].isalpha() and ("a"<=s[i]<="z" or "A"<=s[i]<="Z"): if s[i].upper() not in data and s[i].lower() not in data: count += 1 data.append(s[i]) if count == 10: break if count == 10: for i in data: print(i,end="") else: print("not found")
7-5 jmu-python-求三角形面积及周长 (10 分)
import math a = eval(input()) b = eval(input()) c = eval(input()) s = (a+b+c)/2 area = math.sqrt(s*(s-a)*(s-b)*(s-c)) perimeter = a+b+c print('area={:.2f};perimeter={:.2f}'.format(area, perimeter))
7-4 jmu-python-是否偶数 (10 分)
n = eval(input()) if (n % 2 == 0): print("{}是偶数".format(n)) else: print("{}不是偶数".format(n))
7-3 转换函数使用 (30 分)
a, b = input().split(",") print(int(a, eval(b)))
7-6 重要的事情说N遍 (20 分)
n = input() num = eval(input()) for i in range(1, num+1): print(n+"!", end="")
7-7 计算M和N的多个结果 (10 分)
m = eval(input()) n = eval(input()) print(m+n, end=" ") print(m*n, end=" ") print(m**n, end=" ") print(m%n, end=" ") if m > n: print(m) else: print(n)
7-8 计算 11+12+13+…+m (30 分)
m = eval(input()) sum = 0 for i in range(11, m+1): sum += i print("sum = {}".format(sum))
7-9 找出最大值和最小值 (10 分)
a = list(map(int, input().split(" "))) n = len(a) a.sort() print("Max={}".format(a[n-1])) print("Min={}".format(a[0]))
这篇关于PTA Python第二周题解的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门
- 2024-11-14Python编程入门指南
- 2024-11-13Python基础教程
- 2024-11-12Python编程基础指南
- 2024-11-12Python基础编程教程
- 2024-11-08Python编程基础与实践示例
- 2024-11-07Python编程基础指南
- 2024-11-06Python编程基础入门指南
- 2024-11-06怎么使用python 计算两个GPS的距离功能-icode9专业技术文章分享