Python Exercise 7

Source: Internet
Author: User

#!/usr/bin/python#-*-coding:utf-8-*-defgcd (x, y):#Max male Factor    ifx>y:x%=y whileX:x,y=y%x,xreturnydefLCM (x, y):#least common multiple    returnx*y/gcd (x, y)defJhua (x): T=GCD (x[0],x[1])    return[x[0]/t,x[1]/T]defz42 (): x, y= (120,36)    PrintX, Y,"The least common multiple is", LCM (x, y)PrintX, Y,"The maximum common factor is", gcd (x, y)defz43 ():#Compare the size of a two score    defBijiao (x, y): x, y=Jhua (x), Jhua (y) m,n=x[0]*y[1],x[1]*Y[0]ifM>N:return '>'        elifm<N:return '<'        Else:            return '='x, y=[1235,2356],[1357,2468]    PrintX,bijiao (x and y), ydefz44 ():#Find out the solution of equation 1/x+1/y+1/z+1/a=1    defaddf (x, y): x, y=Jhua (x), Jhua (y)returnJhua ([x[0]*y[1]+x[1]*y[0],y[1]*x[1]]) AI=range (2,13) aII=range (2,43) Num=1 forIinchAI: forJinchAI: forMinchAI: forKinchaII:ifi<=j<=m<=K:r=[I,j,m,k] t=reduce (ADDF, Map (LambdaX:[1, x],r))ift==[1,1]:                            Printnum,r Num+=1defz45 ():defFena (x, y):#the fraction of the molecule 1 is called the Egyptian score. decomposes a fraction A/b into n Egyptian fractions andsh,yu=divmod (x, y) re=[]        ifYu:t=sh+1Re+=[T] y,x=y*t-x,x*T re+=Fena (x, y)Else: Re+=[x/y]returnRePrintFena (99,19)defz46 ():#find the simplest fraction of a molecule that is less than 40 and the denominator equals 40, meaning that the numerator and denominator have no common factor fractions.Num=1 forIinchRange (1,40): Y=40ifGCD (i,y) ==1:            PrintNum,[i,y] Num+=1defz47 ():defdivf (x, y): Yu=[] SH=[] sh1,yu1=divmod (x, y) sh+=[str (SH1),'.']        ifYu1==0:return "'. Join (Sh[:-1])         whileyu1:sh1,yu1=divmod (yu1*10, y) sh+=[Str (SH1)]ifYu1 not inchYu:yu+=[YU1]Else: T=Yu.index (YU1) Sh.insert (t+3,'(') Sh.append (')')                 Break        return "'. Join (SH)PrintDIVF (3737,27000)    PrintDIVF (12,100)    PrintDIVF (120,12)if __name__=='__main__': S=""     forIinchRange (42,48): S+='Z'+str (i) +'() \ n'    exec(s)

Python Exercise 7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.