
自学python
mrxs
俯身凝视深渊,仰头渴望极光
展开
-
My first program written in Python
1.print'Hello World!'2. 一元二次方程的定义是:ax² + bx + c = 0请编写一个函数,返回一元二次方程的两个解。import mathdef quadratic_equation(a, b, c): temp = b * b - 4 * a * c if(temp < 0): return elif (temp == 0):原创 2017-08-22 15:42:55 · 409 阅读 · 0 评论 -
温度转换(python笔记)
#温度转换程序 #TempConvert.py val = input("Please input a number") if val[-1] in ['C', 'c']: f = 1.8 * float(val[0:-1]) + 32 print("temperature"%f) 保留字: 定义变量时,不能与之相同~and | elif | impor原创 2017-08-22 16:01:36 · 3551 阅读 · 0 评论 -
函数(python笔记)
请定义一个 greet() 函数,它包含一个默认参数,如果没有传入,打印 ‘Hello, world.’,如果传入,打印 ‘Hello, xxx.’def greet(n='world'): if n=='world': print'hello, world.', else: print 'hello,', n,'.',greet() greet('B原创 2017-08-22 16:34:35 · 469 阅读 · 0 评论 -
切片(python笔记)
range()函数可以创建一个数列: range(1, 101) [1, 2, 3, …, 100] 请利用切片,取出: 1. 前10个数; 2. 3的倍数; 3. 不大于50的5的倍数。L = range(1, 101)print L[:10],#取前十个 print L[2::3], print L[4:51:5],记住倒数第一个元原创 2017-08-22 19:28:53 · 579 阅读 · 0 评论 -
迭代(python笔记)
Python 的 for循环不仅可以用在list或tuple上,还可以作用在其他任何可迭代对象上。请用for循环迭代数列 1-100 并打印出7的倍数。for i in range(101): if(i%7==0): print i,索引迭代也不是真的按索引访问,而是由 enumerate() 函数自动把每个元素变成 (index, element) 这样的tuple,再迭代原创 2017-08-22 20:00:35 · 377 阅读 · 0 评论 -
复杂表达式(Python笔记)
复杂表达式 使用for循环的迭代不仅可以迭代普通的list,还可以迭代dict。假设有如下的dict:d = { ‘Adam’: 95, ‘Lisa’: 85, ‘Bart’: 59 } 完全可以通过一个复杂的列表生成式把它变成一个 HTML 表格:tds = ['<tr><td>%s</td><td>%s</td></tr>' % (name, score) for name, score i原创 2017-08-22 20:54:05 · 654 阅读 · 0 评论 -
简单时间转换(Python笔记)
简单时间转换 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Discuss Problem Description这道题很简单,你只需要完成分和秒之间的转换即可。 保证输入输出数据均为正整数,且在 int 范围内。 Output一个整数,表示分。 Input一个整数,表示秒。 Example Output2 Exa原创 2017-08-25 21:21:22 · 411 阅读 · 0 评论 -
python 安装教程
感谢博主原创 2018-06-14 11:43:20 · 486 阅读 · 0 评论 -
全字母句(Python)
全字母句(Python) Problem Description 全字母句 (pangram) 指包含字母表中全部 26 种英文字母(不区分大小写)的句子,其常被用于展示英文字体的显示效果。 现在,bLue 得到了很多句子,他想知道哪些句子是全字母句。 Input 输入数据有多组(数据组数不超过 100),到 EOF 结束。 每组数据包含一行长度不超过 100 的字符串。 Outpu...原创 2018-06-27 10:06:55 · 1084 阅读 · 0 评论