第2.1讲- -流程控制求解代数模型(1).pptx - Python 语法基础 流程控� 教师:丛培盛 [email protected]

第2.1讲- -流程控制求解代数模型(1).pptx - Python...

This preview shows page 1 - 7 out of 23 pages.

[email protected] Python 语法基础 流程控制 教师:丛培盛
Image of page 1
2 流控制语句—及列表 计算机程序的语句执行,采用顺序流式方式 改变语句执行的次序,使用流控制语句 常见流控制语句种类 if while 语句 for 语句 break 语句 :打断所在的最内层循环 continue 语句:执行下一次循环,跳过后面的循环体
Image of page 2
3 if 格式 1 if 布尔值表达式 : 语句组 格式 2 if 布尔值表达式 : 语句组 1 else : 语句组 2 格式 3 if 布尔值表达式 : 语句组 1 elif 布尔值表达式 : 语句组 2 else : 语句组 3
Image of page 3
4 求最大值 输入 2 个数,求其中的大者,输出 if 语句例子 运行结果 >>> x=32 y=13 max is:32.0 tempX=input("x=") tempY=input("y=") x=float(tempX) # 字符串转浮点 y=float(tempY) max=x // 先假设 x 是最大的 if max<y: max=y print("max is:",max)
Image of page 4
5 a=4 b=20 c=2 方程有实根 a=4 b=1 c=2 方程没有实根 if 语句例子 2 判断一元二次方程是否有实数根 a=input("a=") b=input("b=") c=input("c=") a=float(a) b=float(b) c=float(c) delta = b*b-4*a*c if (delta >=0): print(" 方程有实根 ") else: print(" 方程没有实根 ") 输入 3 个数,转实数 计算 delta, 决定根
Image of page 5
6 if 例子 3 a=input("a=") a=float(a) b=float(input("b=")) c=float(input("c=")) delta = b*b-4*a*c if (delta >0): print(" 方程有 2 个不同实根 ") elif delta==0: print(" 方程有 2 个相等实根 ") else: print(" 方程没有实根 ") 完善左边的程序,将 2 根求出来 sqrt 函数,在 math
Image of page 6
Image of page 7

You've reached the end of your free preview.

Want to read all 23 pages?

  • Spring '09
  • FAREWELL

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes