In [3]:
#练习1
def sum_mul(end):
    i=1
    total=1
    while i<=end:
        total=total*i
        i=i+1
    return total
m=int(input('请输入m的值'))
n=int(input('请输入n的值'))
k=int(input('请输入k的值'))

print('最终的和是:',sum_mul(m)+sum_mul(n)+sum_mul(k))


请输入m的值3
请输入n的值3
请输入k的值3
最终的和是: 18

In [17]:
#练习2
def fen(end):
    i=1
    total=1
    while i<end:
        if i%2==0:
            total=total+1/(i*2+1)
        if i%2!=0:
            total=total-1/(i*2+1)
        i=i+1
    return total

print(4*fen(1000))
print(4*fen(10000))


3.140592653839794
3.1414926535900345

In [20]:
#练习3
def xz(name,birthday):
    if birthday >= 3.21 and birthday <= 4.19:
        print(name,'您是有个性的白羊座')
    elif birthday >= 4.20 and birthday <= 5.20:
        print(name,'您是有个性的金牛座')
    elif birthday >= 5.21 and birthday <= 6.21:
        print(name,'您是有个性的双子座')
    elif birthday >= 6.22 and birthday <= 7.22:
        print(name,'您是有个性的巨蟹座')
    elif birthday >= 7.23 and birthday <= 8.22:
        print(name,'您是有个性的狮子座')
    elif birthday >= 8.23 and birthday <= 9.22:
        print(name,'您是有个性的处女座')
    elif birthday >= 9.23 and birthday <= 10.23:
        print(name,'您是有个性的天秤座')
    elif birthday >= 10.24 and birthday <= 11.22:
        print(name,'您是有个性的天蝎座')
    elif birthday >= 11.23 and birthday <= 12.21:
        print(name,'您是有个性的射手座')
    elif birthday >= 1.20 and birthday <= 2.18:
        print(name,'您是有个性的水瓶座')
    elif birthday >= 2.19 and birthday <= 3.20:
        print(name,'您是有个性的双鱼座')
    else:
        print(name,'您是有个性的摩羯座')
        
name=input('请输入你的名字')
birthday=float(input('请输入你的生日'))
xz(name,birthday)


请输入你的名字lengxiaoxuan
请输入你的生日1.1
lengxiaoxuan 您是有个性的摩羯座

In [22]:
#练习3
def words(word):
    if (word.endswith('y')):
        print(word[:-1]+'ies')
    elif(word.endswith('s') or word.endswith('x') or word.endswith('ch') or word.endswith('sh')):
        print(word+'es')
    else:
        print(word+'s')
    
word=input('请输入一个单词')
words(word)


请输入一个单词word
words

In [23]:
#挑战性练习(没看懂题目要求)

def a(m,n,k):
    sum=0
    i=0
    while(i<=k):
        sum=sum+m+i
        i=i+1
    return sum

m=int(input('请输入一个数:'))
n=int(input('请输入一个数大于前一个数:'))
k=n-m
print(a(m,n,k))


请输入一个数:2
请输入一个数大于前一个数:6
20