Python 实验3 选择结构程序设计2.doc

上传人:飞****9 文档编号:134196844 上传时间:2020-06-03 格式:DOC 页数:2 大小:22KB
返回 下载 相关 举报
Python 实验3 选择结构程序设计2.doc_第1页
第1页 / 共2页
Python 实验3 选择结构程序设计2.doc_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

《Python 实验3 选择结构程序设计2.doc》由会员分享,可在线阅读,更多相关《Python 实验3 选择结构程序设计2.doc(2页珍藏版)》请在金锄头文库上搜索。

1、实验3 选择结构程序设计(续)【实验目的】 1掌握分支条件语句的使用。2掌握分支嵌套语句的使用。【实验内容】1. 通过Input()函数任意输入三条边长,经过简单的计算后,判断三条边长能否构成三角形,并确定是类型的三角形,如(等边,等腰,一般三角形)。a=input(Please input the length of a:)b=input(Please input the length of b:)c=input(Please input the length of c:)if a+bc and a+cb and b+ca: if a=b=c: print This is an equila

2、teral triangle. if a=b or a=c or b=c: print This is an isosceles triangle. if a!=b!=c: print This is a scalene triangle.else: print These lengths can not form a triangle.2. 密码登录程序。要求:建立一个登录窗口,要求输入帐号和密码。设定用户名为”zhangshan”,密码为“Python123”;若用户名正确,密码正确,则显示“Zhangshan先生,欢迎你!”;如果用户名错误,则显示“用户名错误,请重新输入!”;若密码不正

3、确,显示“对不起,密码错误,无法登录!”。x=raw_input(User:)y=raw_input(Password:)if x=zhangshan and y=Python123: print Welcome,Mr.Zhangshan!if x=zhangshan and y!=Python123: print Wrong password.No right to log-in.while x!=zhangshan and y=Python123: x=raw_input(Wrong users name.Please enter again:) if x=zhangshan: print

4、 Zhangshan先生,欢迎你!3. 设有三个变量a,b,c,分别对三个变量赋值,并对三个变量进行排序。如a=5,b=7,c=6,则排序结果为bca。a=input(Assign a a value:)b=input(Assign b a value:)c=input(Assign c a value:)if abc: print abcif acb: print acbif bac: print bacif bca: print bcaif cab: print cabif cba: print cba4. 计算一元二次方程 ax2+bx+c 的根是公式。因为负数的平方根是虚的,所以可以使

5、用平方根里面的表达式(称为差别式)先进地判别,检查根型。如果判别式是负数,根是虚的。如果判别式是零,只有一个根;如果判别式是正的,有两个根。写一个程序,使用二次方根式得到实根,即忽略虚根。使用判别式确定有一个根或两个根,然后显示出答案。print a*x*2+b*x+c=0a=input(Input a:)b=input(Input b:)c=input(Input c:)if b*2-4*a*c0: x1=-b+(b*2-4*a*c)*0.5/(2*a) x2=-b-(b*2-4*a*c)*0.5/(2*a) print The number of the root of equation:2,x1,x2if b*2-4*a*c=0: x0=-b/(2*a) print The number of the root of equation:1,x0if b*2-4*a*c0: print Non-real complex roots.

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 学术论文 > 管理论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号