python 练习题
python是一个功能很强大的语言,他可以解决各种在数学问题,下面我分享一些练习题供大家参考:
有关正态分布的问题:
# -*- coding: cp936 -*-
import math
a=0
u=0
x=0
while 1:
a =int(input("please input a :"))
ifa<0:
print "请重新输入:"
elifa>0:
break;
u = int(input("please intput u :"))
x = int(input("please intput x :"))
fs =(1/math.sqrt(2*math.pi)*a)*math.exp(0.5*(math.pow(((x-u)/a),2)))
print "this fs is :%.2f"%fs;
关于平抛运动矢量位移:
v0 =10
g= 9.81
#t = int(input("please input a time:"))
#h = v0*t+0.5*g*t**2
#print "this h is :%.2f"%h; while 1:
h =int(input("please input a hight:"))
#h =v0*t+0.5*g*t**2
t1=(-v0+(v0**2-4*0.5*g*(-h))**0.5)/(2*0.5*g)
t2=(-v0-(v0**2-4*0.5*g*(-h))**0.5)/(2*0.5*g)
ift1>0:
print "this time1 is:%.2f"%t1;
ift2>0:
print "this time2 is :%.2f"%t2;
python的函数式编程
判断一个数是不是质数:
>>>f = lambda x:not reduce(lambda x,y:x or y,[x%i==0 for i inrange(2,x)])
>>> f(97)
True
>>> f(96)
False
求最大公约数:
>>> f = lambdam,n:[i for i in range(min(m,n),0,-1) if m%i==0 and n%i==0][0]
>>> f(123,77)
1
>>> f(125,100)
25
计算给定数字的阶乘:
>>> f = lambdax:reduce(lambda x,y:x*y,[i for i in range(1,x+1)])
>>> f(5)
120
>>> zip3 = lambdal1,l2,l3:[(l1[i],l2[i],l3[i]) for i in range(len(l1))]
>>>zip3([1,2,3],['a','b','c'],[1j,2j,3j])
[(1, 'a', 1j), (2, 'b', 2j), (3, 'c', 3j)]
python的reduce函数的应用:
>>> f = lambdal:reduce(lambda x,y:x*y,l)
>>> f(l)
0
>>>f([1,2,2,3,4])
48
蒙特卡洛近似求解
1.求圆周率:
import random
import math
def round_(num):
i=0
number=0.0
whilei<num:
x = random.random()
y = random.random() y_=s(x)
if y<=y_:
number+=1
i+=1
return4*number/num
def s(a):
returnmath.sqrt(1-math.pow(a,2))
2.求面积:
import random
def f(num):
i=0
s=0.0
while i<num:
x = random.random()
#print x
y = random.random()
y_=ft(x)
if y<=y_:
s+=1
i+=1
return s/num def ft(a) :
return a*a
python 练习题的更多相关文章
- Python练习题 028:求3*3矩阵对角线数字之和
[Python练习题 028] 求一个3*3矩阵对角线元素之和 ----------------------------------------------------- 这题解倒是解出来了,但总觉得 ...
- Python练习题 027:对10个数字进行排序
[Python练习题 027] 对10个数字进行排序 --------------------------------------------- 这题没什么好说的,用 str.split(' ') 获 ...
- Python练习题 026:求100以内的素数
[Python练习题 026] 求100以内的素数. ------------------------------------------------- 奇怪,求解素数的题,之前不是做过了吗?难道是想 ...
- Python练习题 025:判断回文数
[Python练习题 025] 一个5位数,判断它是不是回文数.即12321是回文数,个位与万位相同,十位与千位相同. ---------------------------------------- ...
- Python练习题 024:求位数及逆序打印
[Python练习题 024] 给一个不多于5位的正整数,要求:一.求它是几位数,二.逆序打印出各位数字. ---------------------------------------------- ...
- Python练习题 004:判断某日期是该年的第几天
[Python练习题 004]输入某年某月某日,判断这一天是这一年的第几天? ---------------------------------------------- 这题竟然写了 28 行代码! ...
- Python练习题-1.使用匿名函数对1~1000求和,代码力求简洁。
Python 练习 标签(空格分隔): Python Python练习题 Python知识点 一.使用匿名函数对1~1000求和,代码力求简洁. 答案: In [1]: from functools ...
- PYTHON练习题 二. 使用random中的randint函数随机生成一个1~100之间的预设整数让用户键盘输入所猜的数。
Python 练习 标签: Python Python练习题 Python知识点 二. 使用random中的randint函数随机生成一个1~100之间的预设整数让用户键盘输入所猜的数,如果大于预设的 ...
- python 基础 2.8 python练习题
python 练习题: #/usr/bin/python #coding=utf-8 #@Time :2017/10/26 9:38 #@Auther :liuzhenchuan #@File ...
- Python练习题2
如果真的想学精,学什么都不是好学的,如果真的想把Python学的出神入化,几乎自己想做什么都可以,就要下定恒心,坚持下去. 接下来继续更新Python练习题2,通过更新前一部的练习题让自己也学到了不少 ...
随机推荐
- Jedis操作Redis数据库
添加Maven依赖: <dependencies> <!-- 单元测试 --> <dependency> <groupId>junit</grou ...
- MyBatis(3.2.3) - Configuring MyBatis using XML, Mappers
Mapper XML files contain the mapped SQL statements that will be executed by the application using st ...
- JAVA之数据溢出
Integer在java中属于包装类,既能用于字符串与整型的转换,也能用于拆箱与装箱 package ABC; public class A{ public static void main(Stri ...
- javascript笔记——密码组合规则
//6-16个字符,字母加数字或符号的组合密码[必须全部包含] var filter = /^(?=.*[0-9])(?=.*[a-z])(?=.*[!@#$%^&*])(?=.*[A-Z]) ...
- Js 对象三
一.screen对象 Width:屏幕的宽度 Height:屏幕的高度 availWidth:屏幕的有效宽度 availhHeight:屏幕的有效高度 (不包含任务栏) colorDepth:色深 二 ...
- @Autowired与@Resource用法
官方文档中有这样一段话. If you intend to express annotation-driven injection by name, do not primarily use @Aut ...
- TransparentBlt函数的使用注意事项
今天客户需要在软件上需要添加一个自己公司的Logo,要求使用镂空透明的形式展现,本来以为很简单的工作没想到在MFC下这么复杂.Logo为BMP格式,白色背景. 以为和在按钮上显示控件差不多,先导入BI ...
- CSDN 自动评论
转载说明 本篇文章可能已经更新,最新文章请转:http://www.sollyu.com/csdn-auto-reviews/ 说明 当打开http://download.csdn.net/my/do ...
- Poj 2583 Series Determination
1.Link: http://poj.org/problem?id=2583 2.Content: Series Determination Time Limit: 1000MS Memory L ...
- linux 安装mysql后修改密码出现问题
新安装的mysql 执行命令时候出现错误: 一 错误信息: ERROR 1045 (28000): Access denied for user 'mysql'@'localhost' (using ...