python3练习100题——021】的更多相关文章

题目很容易,只要理清了数学思想就可以解出来,所以本来不是很喜欢这种题. 后来看到有大神用递归解,觉得还是很值得学习的. 原题链接:http://www.runoob.com/python/python-exercise-example21.html 题目:猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个第二天早上又将剩下的桃子吃掉一半,又多吃了一个.以后每天早上都吃了前一天剩下的一半零一个.到第10天早上想再吃时,见只剩下一个桃子了.求第一天共摘了多少. 我的代码: x…
今天继续-答案都会通过python3测试- 原题链接:http://www.runoob.com/python/python-exercise-example3.html 题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少? 我的代码: import math def fun(): for i in range(-100,10000): #i的range范围不够精确,具有偶然性 x=math.sqrt(i+100)%1 y=math.sqrt(i+26…
因为特殊原因,昨天没有做题.今天继续- 原题链接:http://www.runoob.com/python/python-exercise-example2.html 题目: 企业发放的奖金根据利润提成.利润(I)低于或等于10万元时,奖金可提10%: 利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%: 20万到40万之间时,高于20万元的部分,可提成5%: 40万到60万之间时高于40万元的部分,可提成3%: 60万到100万之间时,高于60…
继续做题-经过python3的测试 原题链接:http://www.runoob.com/python/python-exercise-example4.html 题目:输入某年某月某日,判断这一天是这一年的第几天? 我的代码: year=int(input("please input the year:")) month=int(input("please input the month:")) day=int(input("please input t…
原题链接:http://www.runoob.com/python/python-exercise-example36.html 题目:求100之内的素数. 之前有类似的题,所以这次遇到觉得很容易了,直接写了一个可以一直求素数下去的代码: def fun(): k=1 while True: k+=1 n=0 for i in range(2,k): if k%i==0: n=1 break if n==0: print(k) 如果要限定在100之内,改变第一个循环为for,设置range即可.…
原题链接:http://www.runoob.com/python/python-exercise-example34.html 题目:文本颜色设置. 学习了一下python3 的文本颜色设置. 其实没有太搞懂.…
原题链接:http://www.runoob.com/python/python-exercise-example20.html 题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半:再落下,求它在第10次落地时,共经过多少米?第10次反弹多高? 我的代码: def ball(): times=int(input("Hou many times the ball hit the floor?")) h=100.0 record=[] length=100 for i in r…
熟悉的水仙花数来了,,,... 原题链接:http://www.runoob.com/python/python-exercise-example13.html 题目:打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身.例如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方. 我的代码: def fun(): num=[] for i in range(100,1000): a=i//1…
题目:画图,学用circle画圆形. 可以用turtle.circle画图. import turtle turtle.setup(0.6,0.6) turtle.pensize(3) turtle.pencolor("green") turtle.circle(100)…
题目:输出一个随机数. 程序分析:使用 random 模块. import random print( random.randint(1,10) ) # 产生 1 到 10 的一个整数型随机数 print( random.random() ) # 产生 0 到 1 之间的随机浮点数 print( random.uniform(1.1,5.4) ) # 产生 1.1 到 5.4 之间的随机浮点数,区间可以不是整数 print( random.choice('tomorrow') ) # 从序列中随…