python趣味编程入门 百度云_python趣味编程100例

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

001 # -*- coding: cp936 -*-

002 from math import acos,sqrt

003 #第一章----最简单的问题

004 #《c趣味编程》1-10题

005 #21:39 2007-1-5

006 def genfunc(n,k):

007     head = """

008 def permute(seq0):

009     result = [] """

010     boiler = """

011 for counter%i in seq%i:

012     seq%i = seq%i[:]

013     seq%i.remove(counter%i)"""

014     for i in range(1,k+1):

015         space = '    '*i

016         head = head + boiler.replace('\n','\n'+space)%(i,i-1,i,i-1,i,i)

017     temp = ','.join([ 'counter%i'%(x) for x in range(1,k+1) ] )

018     head = head + '\n' + space + "    result.append(''.join([%s]))"%(temp)

019     return head + '\n    return result\n'

020 def zz1(e,f):

021     ss=[]

022     for m in e:

023         s1=" "*62

024         k=f(m)

025         s2=s1[:k]+"*"+s1[k+1:]

026         k=62-k

027         s3=s2[:k]+"*"+s2[k+1:]

028         ss+=[s3]

029     return ss

030

031 def z1():

032     #绘制余弦曲线

033     k=zz1(range(10,-11,-1),lambda m: int(acos(m/10.0)*10))

034     for n in k:

035         print n

036

037 def z2():

038     #绘制余弦曲线和一条直线

039     k=zz1(range(10,-11,-1),lambda m: int(acos(m/10.0)*10))

040     def g(e,gg,f):

041         ss=[]

042         for m in e:

043             s1=gg[m]

044             k=f(m)

045             if 0

046                 s2=s1[:k]+"#"+s1[k+1:]

047             else :

048                 s2=s1

049             ss+=[s2]

050         return ss

051     k=g(range(20),k,lambda m: int(4.5*(m-1)+3.1))

052     for n in k:

053         print n

054

055 def z3():

056     #绘制圆

057     k=zz1(range(10,-11,-1),lambda m: int(30-2.5*int(sqrt(100-m*m))))

058     for n in k:

059         print n

060 def z4():

061     '''唱歌大奖比赛,去掉最高分和最低分得到平均分

062     '''

063     def g(n):

064         x=max(n)

065         nn=min(n)

066         print "最高分",x

067         print "最低分",nn

068         print "平均分",(sum(n)-x-nn)/(len(n)-2)

069         return

070     m=[1,2,3,4,5,6,7]

071     g (m)

072

073 def z5():

074     #555555的最大的三位数约数是多少

075     print max(filter(lambda x: 555555%x==0,range(100,999)))

076 def z6():

077     #13的20次方的最后三位数是多少

078     def zz6(x,y,z):

079         xx=[x]*y

080         return reduce(lambda x,y:x*y%z, xx)

081     print zz6(13,20,1000)

082

083 def z7():

084     #100 !的末尾有多少个0

085     def g(n):

086         k=0

087         for m in range(1,n+1):

088             if m%25==0 :

089                 k+=2

090             elif m%5==0 :

091                 k+=1

092         return k

093     print g(100)

094 def z8():

095     #5个取3个的排列的总数以及方法

096     functext = genfunc(9,3)

097     print functext

098     exec(functext)

099     s=permute(list("12345"))

100     print s,len(s)

101 def z9():

102     #计算杨辉三角形

103     g = lambda x,y: (y==1 or y==x+1) and 1 or g(x-1,y-1)+g(x-1,y)

104     for m in range(1,13):

105         print ' '*2*(13-m),

106         for n in range(1,m+2):

107             print  str(g(m,n)).center(4),

108         print

109 def z10():

110     #把10进制度变成2进制

111     def g(n,k):

112         d=n

113         s=""

114         while d!=0:

115             d,f=divmod(d,k)

116             s=str(f)+s

117         return s

118     print g(234,2)

119 if __name__ == '__main__':

120     s=""

121     for i in range(1,11):

122         s+='z'+str(i)+'()\n'

123     exec(s)

124

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Chapter 2 Magic coins example. magic_coins1.py Chapter 3 Favourite sports. favourite_sports.py Furniture placeholder. furniture_placeholder.py A list of lists. list_of_lists.py A letter from Malcolm Dithering dithering_letter.py Escaping quotes quote_escaping.py The Wizard List wizard_list.py Chapter 4 The turtle draws a square. turtle1.py The turtle draws two parallel lines. turtle2.py Chapter 5 If statements if_statements.py Conditions in if-statements. conditions.py Else-if (elif) statements. elif_statements.py Strings and numbers. strings_and_numbers.py Chapter 6 Five Hellos. five_hellos.py Huge hairy pants (example 1). huge_hairy_pants1.py Huge hairy pants (example 2). huge_hairy_pants2.py Magic coins (example 2). magic_coins2.py A while-loop with multiple conditions. while_loop_multiple_conditions.py Looping through the wizard list. wizard_list_loop.py Chapter 7 A function to calculate your savings. savings.py Building a spaceship. spaceship_building.py Test function (example 1). test_function1.py Test function (example 2). test_function2.py Your age function. your_age.py Chapter 8 Giraffes (example 1). giraffes1.py Giraffes (example 2). giraffes2.py Three turtles. three_turtles.py Chapter 9 Using the abs (absolute) function. abs_function.py Using the exec (execute) function. exec_function.py Using the len (length) function. len_function.py Using the max and min functions. max_and_min.py Using the range function. range_function.py Using the sum function. range_function.py Opening a file. opening_a_file.py Writing to a file. writing_to_a_file.py Chapter 10 Copying objects (example 1). copying_objects1.py Copying objects (example 2). copying_objects1.py Guess a random number. guess_a_number.py Random desserts. random_desserts.py Using the time module. timing_lots_of_numbers.py Using pickle to save information. pickle_saving.py Using pickle to load information. pickle_loading.py Chapter 11 Drawing an eight point star. eight_point_star.py Drawing a many point star. many_point_star.py Drawing a spiral star. spiral_star.py Drawing a nine point star. nine_point_star.py Drawing a car. car.py Drawing a yellow circle. yellow_circle.py Drawing a filled green circle. green_circle.py Drawing a dark-green circle. dark_green_circle.py Drawing squares using a function. square_function.py Drawing filled and unfilled squares. filled_squares.py Drawing stars using a function. star_function.py Chapter 12 Clickable button (example 1). clickable_button1.py Clickable button (example 2). clickable_button2.py Drawing a diagonal line. diagonal_line.py Drawing a square. square.py Drawing a horizontal rectangle. horizonal_rectangle.py Drawing a vertical rectangle. horizonal_rectangle.py Drawing random rectangles. random_rectangles.py Drawing coloured rectangles. coloured_rectangles.py Using the color chooser. rectangle_colorchooser.py Drawing arcs. drawing_arcs.py Drawing polygons. drawing_polygons.py Drawing text. drawing_text.py Drawing images. drawing_images.py Basic animation (example 1). basic_animation1.py Basic animation (example 2). basic_animation2.py Using events (example 1). using_events1.py Using events (example 2). using_events1.py Using the move function. using_move.py Using the itemconfig function. using_itemconfig.py Chapter 13 Bounce (example 1) - this one doesn't do anything when it's run. bounce1.py Bounce (example 2) - stationary ball. bounce2.py Bounce (example 3) - ball moving upwards. bounce3.py Bounce (example 4) - ball moving up and down. bounce4.py Bounce (example 5) - ball moving around the screen. bounce5.py Chapter 14 Bounce (example 6) - adding the paddle. bounce6.py Bounce (example 7) - moving paddle. bounce6.py Bounce (example 8) - bouncing the ball when it hits the paddle. bounce6.py Bounce (example 9) - ending the game when the ball hits the floor. bounce6.py Chapter 15 Transparent Image - 27 by 30 pixels. transparent-image.gif 6 Stick Figure Images - left and right. stickfigure.zip 3 Platform images. platform.zip 2 Door images. door.zip Background image. background.gif Chapter 16 Stickman Game, version 1 - displaying the background. stickmangame1.py Stickman Game, version 2 - adding the within functions. stickmangame2.py Stickman Game, version 3 - adding the platform. stickmangame3.py Stickman Game, version 4 - adding lots of platforms. stickmangame4.py Chapter 17 Stick figure sprite class. stickfiguresprite.py Stickman Game, version 5 - adding the stick figure. stickmangame5.py Chapter 18 Stickman Game, version 6 - animating the stick figure. stickmangame6.py Stickman Game, version 6 - adding the door sprite. stickmangame7.py Afterword Pygame2 example. pygame-example.py Hello World Java example. HelloWorld.java Hello World C example. helloworld.c Hello World C++ example. helloworld.cpp Hello World C# example. helloworld.cs Hello World PHP example. helloworld.php Hello World Objective-C example. helloworld.m Hello World Perl example. helloworld.pl Hello World Ruby example. helloworld.rb Hello World Javascript example. helloworld.js Hello World Javascript Browser example. helloworld-js.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值