Python—经典练手题目汇总(Python – Summary of classic hand training topics)

Python—经典练手题目汇总

# 1、有1020个西瓜,第一天卖掉总数的一半后又多卖出两个,以后每天卖剩下的一半多两# 个,问几天以后能卖完?

day=0
xg=1020
for i in range(999):
    day+=1
    xg=xg/2-2
    if xg==0:
        print(day)

# 2、猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不过瘾,又多吃了一# 个,第二天早上又将剩下的桃子吃了一半,又多吃一个,以后每天都吃了前一天剩下的# 一半零一个。到第10天早上想再吃时,见只剩下一个桃子。求第一天共摘了多少个?

peach = 1
for i in range(9):
    peach = (peach + 1)  * 2
print(peach)

# 3、有个人想知道,一年之内一对兔子能繁殖多少对?于是就筑了一道围墙把一对兔子关在# 里面。已知一对兔子每个月可以生一对小兔子,而一对兔子从出生后第3个月起每月生# 一对小兔子。假如一年内没有发生死亡现象,那么,一对兔子一年内(12个月)能繁殖#成多少对?分析:兔子的规律为数列,1,1,2,3,5,8,13,21

one=1
two=1
number=0
for i in range (3,13):
    number=one+two
    one=two
    two=number
    print(number)

# 4、计算1000以内所有不能被7整除的整数之和

zonghe=0
for i in range( 1001):
  if i % 7 != 0 :
        zonghe += i
print( zonghe)

# 5、计算1+2-3+4-5+6-7..+100的结果//注意审题

number=1
for i in range(2,101):
    if i%2==0:
        number+=i
    else:
        number-=i
print(number)

# 6、一张纸的厚度大约是0.08mm,对折多少次之后能达到或超过珠穆朗玛峰的高度(8848.13# 米)

paper=0.00008
cishu=0
for i in range(9999):
    paper*=2
    cishu+=1
    if paper>=8848.13:
        break
print(cishu)

# 7、一球从100米高度自由落下,每次落地后反跳回原高度的一# ;再落下,求它在第10次落地时,共经过多少米?第10次反弹多高

high=100
m=0
for i in range(1,11):
    m=100/(2**i)
    if i<10:
        high=high+(m*2)
    print("在第十次经过了:",high)
    print("第十次反弹高度为:",m)

# 8、每个做父母的都关心自己孩子成人后的身高,据有关生理卫生知识与数理统计分析表明,影响小孩成# 人后身高的因素有遗传、饮食习惯与坚持体育锻炼等。小孩成人后的身高与其父母的身高和自身的性# 别密切相关# 设faHeiqht为其父身高,moHeight为其母身高,身高预测公式为:# 男性成人时身高=(faHeight+moHeiaht*0.54# 女性成人时身高=(faHeiaht*0.923+moHeiaht)/2# 此外,如果喜爱体育锻炼,那么可增加身高2%,如果有良好的卫生饮食习惯,那么可增加身高1.5%。# 利用给定公式和身高预测方法对你的身高进行预测# 要求父母的身高、是否爱好体育锻炼等参数从键盘输入

SEX=input("请输入您的性别(男|女):")
dad_Height=float(input("请输入您父亲身高:"))
mami_Height=float(input("请输入您母亲身高:"))
PE=input("您是否爱好锻炼(是|否):")
EAT=input("您的饮食习惯是否良好(是|否):")

a=1
b=1
if PE == "是":
    a=1.02
if EAT == "是":
    b=1.015

if SEX == "男":
    result=(dad_Height + mami_Height) * 0.54 * a *b
else:
    result=(dad_Height * 0.923 + mami_Height) / 2 * a *b
print("您的身高是:"+str(result))    
————————

Python – Summary of classic hand training topics

#1. There are 1020 watermelons. After half of the total is sold on the first day, two more are sold. After that, the remaining half is sold more than two # every day. How many days will it be sold out?

day=0
xg=1020
for i in range(999):
    day+=1
    xg=xg/2-2
    if xg==0:
        print(day)

#2. The problem of monkeys eating peaches: on the first day, monkeys picked several peaches and ate half of them immediately. They didn’t enjoy it, so they ate one # more. The next morning, they ate half of the remaining peaches and one more. Later, they ate the remaining half and one of the # peaches of the previous day every day. When I wanted to eat again on the 10th morning, I saw that there was only one peach left. How many were picked on the first day?

peach = 1
for i in range(9):
    peach = (peach + 1)  * 2
print(peach)

#3. Someone wants to know how many pairs of rabbits can breed in a year? So a fence was built to keep a pair of rabbits in # it. It is known that a pair of rabbits can give birth to a pair of rabbits every month, and a pair of rabbits give birth to # a pair of rabbits every month from the third month after birth. If there is no death in a year, how many pairs can a pair of rabbits breed # into in a year (12 months)? Analysis: the rule of rabbits is sequence, 1, 1, 2, 3, 5, 8, 13, 21

one=1
two=1
number=0
for i in range (3,13):
    number=one+two
    one=two
    two=number
    print(number)

#4. Calculate the sum of all integers within 1000 that cannot be divided by 7

zonghe=0
for i in range( 1001):
  if i % 7 != 0 :
        zonghe += i
print( zonghe)

#5. Calculate 1 + 2-3 + 4-5 + 6-7+ 100 / / pay attention to the examination

number=1
for i in range(2,101):
    if i%2==0:
        number+=i
    else:
        number-=i
print(number)

#6. The thickness of a piece of paper is about 0.08mm. How many times can it reach or exceed the height of Mount Everest (8848.13# meters)

paper=0.00008
cishu=0
for i in range(9999):
    paper*=2
    cishu+=1
    if paper>=8848.13:
        break
print(cishu)

#7. A ball falls freely from a height of 100 meters and jumps back to one #; How many meters will it pass on the 10th landing? How high is the 10th rebound

high=100
m=0
for i in range(1,11):
    m=100/(2**i)
    if i<10:
        high=high+(m*2)
    print("在第十次经过了:",high)
    print("第十次反弹高度为:",m)

#8. Every parent is concerned about his or her child’s height after adulthood. According to relevant physiological and health knowledge and mathematical statistical analysis, the factors affecting the child’s height after adulthood include heredity, eating habits and physical exercise. The height of a child in adulthood is closely related to the height of his parents and his own sex # type # let faheiqht be the height of his father and moheight be the height of his mother, and the height prediction formula is: # male adult height = (faheight + moheiaht * 0.54 # female adult height = (faheiaht * 0.923 + moheiaht) / 2# in addition, if he likes physical exercise, he can increase his height by 2%, If you have good hygienic eating habits, you can increase your height by 1.5%# Using the given formula and height prediction method to predict your height # requires parents’ height, whether they like physical exercise and other parameters to be input from the keyboard

SEX=input("请输入您的性别(男|女):")
dad_Height=float(input("请输入您父亲身高:"))
mami_Height=float(input("请输入您母亲身高:"))
PE=input("您是否爱好锻炼(是|否):")
EAT=input("您的饮食习惯是否良好(是|否):")

a=1
b=1
if PE == "是":
    a=1.02
if EAT == "是":
    b=1.015

if SEX == "男":
    result=(dad_Height + mami_Height) * 0.54 * a *b
else:
    result=(dad_Height * 0.923 + mami_Height) / 2 * a *b
print("您的身高是:"+str(result))