Lecture 7_2: Lists and mutability, dictionaries, pseudocode, introduction to efficiency
来源:互联网 发布:淘宝达人在哪里登录 编辑:程序博客网 时间:2024/06/11 10:20
# example code, Lecture 7, Fall 2008import math#get baseinputOK = Falsewhile not inputOK: base = float(input('Enter base:')) #we get str in python 3x from input, we need to convert str to float. if type(base) == type(1.0): inputOK = True else: print('Enter, Base must be a floating point number.')#get heightinputOK = Falsewhile not inputOK: height = float(input('Enter height:')) if type(height) == type(1.0): inputOK = True else: print('Error, Height must be a floating point number.')hyp = math.sqrt(base*base + height*height)print ('Base:' + str(base) + '.height:' + str(height) + '.hyp:' + str(hyp))import mathdef getFloat(requestMsg, errorMsg): inputOK = False while not inputOK: Val = input(requestMsg) if type(Val) == type(1.0): inputOK = True else: print(errorMsg) return Valbase = getFloat('Enter base:', 'Error: base must be a float')height = getFloat('Enter height:', 'Error: height must be a float')hyp = math.sqrt(base*base + height*height)print ('Base:' + str(base) + '.height:' + str(height) + '.hyp:' + str(hyp))# get baseinputOK = Falsewhile not inputOK: try: # user can pass 'inf', 'nan', no error will be raised # should we check this cases? base = float(input('Enter base:')) except ValueError: print('Base must be an integer or floating point number.') else: inputOK = True
阅读全文
0 0
- Lecture 7_2: Lists and mutability, dictionaries, pseudocode, introduction to efficiency
- Lecture 7_1: Lists and mutability, dictionaries, pseudocode, introduction to efficiency
- Lecture 6: Bisection methods, Newton/Raphson, introduction to lists
- Python学习笔记(7)Mouse Input, More Lists and Dictionaries
- Lecture 9: Mutability & Immutability
- Lecture 4: Decomposition and abstraction through functions; introduction to recursion
- Python 入门教程 8 ---- Python Lists and Dictionaries
- Python学习——Lists and Dictionaries
- 6.00 Introduction to Computer Science and Programming Lec 8: Efficiency and Order of Growth
- Introduction to Access Lists
- 6.00 Introduction to Computer Science and Programming Lec 9: Lecture 9: Memory and Search Methods
- Introduction to Linear Algebra Lecture 1
- An Introduction to Python Lists
- An Introduction to Python Lists
- Sorting Lists of Dictionaries
- 【CS231n winter2016 Lecture 4 (Backpropagation ,Introduction to neural networks)】
- CS 20SI|Lecture 1 Introduction to TensorFlow
- Lecture note 1: Introduction to TensorFlow(斯坦福Tensorflow课程)
- 在mybatis报错Open quote is expected for attribute "property" associated with an element type "result".
- mybatis入门基础(四)----输入映射和输出映射
- 程序源的情感生活
- postgres创建用户,修改用户密码,创建数据库
- mybatis入门基础(五)----动态SQL
- Lecture 7_2: Lists and mutability, dictionaries, pseudocode, introduction to efficiency
- 算法分析与设计课程——LeetCode刷题之Reverse Integer
- wr720n v4 折腾笔记(二):刷入不死Uboot
- urllib异常处理中HTTPError和URLError混用的注意事项
- Redis 哈希(Hash)
- JSTL, EL 获取数据和遍历
- mybatis入门基础(六)----高级映射(一对一,一对多,多对多)
- 第一单元作业
- Spring Boot 部署与服务配置详解