Python编程与数据分析基础 入门(一) 内置函数的基本使用

写在前面,本系列文章仅是对自己学习的记录,同时方便以后参考、温习、巩固

1. 计算三角形面积
a = float(input())
b = float(input())
c = float(input())
while a+b<c or a+c<b or b+c<a:  
    a = float(input())
    b = float(input())
    c = float(input())
# 海伦公式求三角形面积
s = (a+b+c)/2
area = (s*(s-a)*(s-b)*(s-c))**(1/2)
print('%0.2f' % area)
2. 交换两个数
a = input()
b = input()
temp = None
temp = a
a = b
b = temp
print(a,b)
3. 计算表达式

这里需要注意的是:cos*(a*(x+1)+b)/2) 比数学公式多了乘号*

import math
a = 2
b = 3
x = 5
print(math.cos(a*(x+1)+b)/2)
4. 计算正方形周长和面积
a = 5
perimeter = 4*a
area  = a**2
print(perimeter,area)
5.列表向量内积

向量内积定义

input()得到的是字符串,需要算数运算还需强制转换 int(input())

from operator import mul
from functools import reduce
a = eval(input())
b = eval(input())
print(sum(map(mul,a,b)))
6.列表元素乘积

mul ---- multiplication 的英文简写,具体用法另行参考

from operator import mul
from functools import reduce
a = eval(input())
print(reduce(mul,a))
7. 列表元素绝对值最大值
a = eval(input())
print(max(a,key=abs))
8. 列表位数
a = eval(input()) 
# 最里层的map返回str()后的list可迭代对象,最外层的map是返回计算list中元素的字符串长度len()形成的可迭代对象
print(list(map(len,map(str,a))))
9.列表降序排列
data = eval(input())
print(sorted(data, reverse = True))
10.列表平均值
from functools import reduce
from operator import add
a = eval(input())
print('平均值为:',round((reduce(add,a)/len(a)),2))

第一次写博客,数学公式,各种文档技术应用还不熟练,需加强练习

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值