In [ ]:
#practice 1
def multiple(end):
i=1
mul=1
while i<=end :
mul*=i
i+=1
return mul
n1=int(input("please enter a numbers"))
n2=int(input("please enter a numbers"))
n3=int(input("please enter a numbers"))
print('the result is: ',multiple(n1)+multiple(n2)+multiple(n3))
In [2]:
#practice 2
def add(end):
temp=1
bla=0
while temp<=2*end-1 :
bla+=1/temp
temp+=2
return bla
print(4*add(1000),4*add(100000),sep=' ')
In [3]:
## practice 3
def con (month,day):
if (month==1 and day>=20) or(month==2 and day<=18) :
print(name,", you are 水瓶座!")
if (month==2 and day>=19) or(month==3 and day<=20) :
print(name,", you are 双鱼座!")
if (month==3 and day>=21) or(month==4 and day<=19) :
print(name,", you are 白羊座!")
if (month==4 and day>=20) or(month==5 and day<=20) :
print(name,", you are 金牛座!")
if (month==5 and day>=21) or(month==6 and day<=21) :
print(name,", you are 双子座!")
if (month==6 and day>=22) or(month==7 and day<=22) :
print(name,", you are 巨蟹座!")
if (month==7 and day>=23) or(month==8 and day<=22) :
print(name,", you are 狮子座!")
if (month==8 and day>=23) or(month==9 and day<=22) :
print(name,", you are 处女座!")
if (month==9 and day>=23) or(month==10 and day<=23) :
print(name,", you are 天秤座!")
if (month==10 and day>=24) or(month==11 and day<=22) :
print(name,", you are 天蝎座!")
if (month==11 and day>=23) or(month==12 and day<=21) :
print(name,", you are 射手座!")
if (month==12 and day>=22) or(month==1 and day<=19) :
print(name,", you are 摩羯座!")
print("有生之年居然碰到信星座的猿……")
def convert(word) :
if word=="have" :
print("has")
elif word=="is" or word=="am" or word=="are" :
print("is")
elif word.endswith('o') :
print(word,"es",sep='')
elif word.endswith('s') or word.endswith('x') or word.endswith('sh') or word.endswith('ch') or word.endswith('e') :
print(word,'es',sep='')
elif ((word.endswith('ay') or word.endswith('ey') or word.endswith('iy') or word.endswith('oy') or word.endswith('uy'))!=1) and word.endswith('y') :
print(word[:-1],'ies',sep='')
else :
print(word,"s",sep='')
name=input('please enter your name: ')
month=int(input("please enter the month of your birth"))
day=int(input("please enter the day of your birth"))
print(con(month,day))
word=input('please enter the a verb: ')
convert(word)
In [ ]:
## challenge
def add(begin,end,gap) :
i=begin
total=0
while i<=end :
total+=i
i+=gap
return total
m=int(input('please enter m :'))
n=int(input('please enter n :'))
k=int(input('please enter k :'))
print('the total is : ',add(m,n,k))
In [ ]: