- 博客(9)
- 收藏
- 关注
原创 帕斯卡三角形 python
题目出自python入门经典第六章课后题 解决思路如下: 每一行开始与结尾人为插入0元素,便于计算,在最后输出的时候不显示就可以了 lines = input("Input the lines:") while not lines.isdigit(): print("Please enter an integer:") lines = input("Input the lines:...
2019-10-23 11:27:51 1326 2
原创 葛底斯堡演说 只出现一次单词
关于python入门经典的葛底斯堡演说 def analyseFile(File): words = [] for line in File: lineWord = line.split() for word in lineWord: word.lower() word.strip(',.') ...
2019-10-22 22:10:38 573
原创 pycharm每次进去都要insert问题
当时第二次下载pycharm的时候,把所有的插件都下载了,其中第一个插件INSTALL Vim Emulation提示说新手不建议下载,但是还是太年轻… 总之,解决办法很简单 看上图,红圈里本来有勾的点一下就关闭了 ...
2019-10-22 10:23:34 1308 1
原创 pycharm各种警告问题
shadows name from outer scope 这种警告是函数内部的名称与外部名称重复了,看下面例子 def cleanword(word): # Return word in lower case stripped of whitespace return word.strip().lower() for word in datafile: word = ...
2019-10-22 10:18:36 2707
原创 for-else结构
这个结构是在python学习字符串时发现的具体代码如下: for index, letter in enumerate(river): if letter == target: print("Letter found index is ", index) break else: print("Not found") if-else结构的运行顺序是如...
2019-10-21 16:27:28 355
原创 python自学笔记04
字符串 索引分片 python采用半开区间,计数从0开始 eg. str[3:5] 获取的是原字符串第4和第5的位置。 拓展分片 分片可以有三个参数,第三个参数表示步长,正数表示从前开始,负数表示从后开始。 字符串操作 连接和重复 str_one = "hello" str_two = "world" str_one + str_two Out[7]: 'helloworld' s...
2019-10-21 16:24:45 81
原创 python自学笔记03
巴比伦平方根 一个变量值到底是int还是float,对程序的影响要考虑到。 算法本身很简单,一个要求平方根的值num,一个提前给的猜测数guess 如果guess就是num的平方根,num/guess的值应该与guess相同,取平均后应该还是guess。说明找到正确的平方根。 我试了试猜测值与猜测次数的关系,比如对于100,测试从1到100作为初始测试值算法总的需要的猜测次数。 是一个“对称”的结...
2019-10-17 22:19:02 60
原创 python自学笔记02
循环 在完全数中,最后可以输出三种结果` if sumOfDivisors == theNum: print(theNum, "is a perfect number") elif sumOfDivisors < theNum: print(theNum, "is a deficient number") else: print(theNum, "is a abund...
2019-10-17 22:18:52 64
原创 python自学笔记01
从python入门经典这本书开始,可能是一些可有可无的点。尽量按照顺序来进行 使用的是PyCharm 计算圆周长 python3.0中没有了raw_input,而是与input合并,所以只能使用input,可以接受任何类型的输入 在结果中想要得到两行输出,使用换行符\n即可:print(“The circumference is :”, circumference, “\nThe area is...
2019-10-15 19:24:30 67
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人