61、打印出杨辉三角形。

#python3.7
from sys import stdout if __name__ == '__main__':
a = []
for i in range(10):
a.append([])
for j in range(10):
a[i].append(0)
for i in range(10):
a[i][0] = 1
a[i][i] = 1
for i in range(2,10):
for j in range(1,i):
a[i][j] = a[i - 1][j-1] + a[i - 1][j]
for i in range(10):
for j in range(i + 1):
stdout.write(str(a[i][j]))
stdout.write(' ')
print()

62、查找字符串。

#python3.7

sStr1 = 'language'
sStr2 = 'age'
print(sStr1.find(sStr2)) 结果:
5

63、使用Tkinter画椭圆。

#python3.7
from tkinter import * if __name__ == '__main__':
x = 360
y = 160
top = y - 30
bottom = y - 30 canvas = Canvas(width = 400, height = 600, bg = 'white')
for i in range(20):
canvas.create_oval(250 - top, 250 - bottom, 250 + top, 250 + bottom)
top -= 5
bottom += 5
canvas.pack()
mainloop()

64、利用ellipse 和 rectangle 画图。

#python3.7
from tkinter import * if __name__ == '__main__':
canvas = Canvas(width = 400, height = 600, bg = 'white')
left = 20
right = 50
top = 50
num = 15
for i in range(num):
canvas.create_oval(250 - right, 250 - left, 250 + right, 250 + left)
canvas.create_oval(250 - 20, 250 - top, 250 + 20, 250 + top)
canvas.create_oval(20 - 2 * i, 20 - 2 * i, 10 * (i + 2), 10 * (i + 2))
right += 5
left += 5
top += 10 canvas.pack()
mainloop()

65、一个最优美的图案。

#python3.7
from tkinter import *
import math class PTS:
def __init__(self):
self.x = 0
self.y = 0
points = [] def LineToDemo():
screenx = 400
screeny = 400
canvas = Canvas(width = screenx, height = screeny, bg = 'white') AspectRatio = 0.85
MAXPTS = 15
h = screeny
w = screenx
xcenter = w / 2
ycenter = h / 2
radius = (h - 30) / (AspectRatio * 2) - 20
step = 360 / MAXPTS
angle = 0.0
for i in range(MAXPTS):
rads = angle * math.pi / 180.0
p = PTS()
p.x = xcenter + int(math.cos(rads) * radius)
p.y = ycenter - int(math.sin(rads) * radius * AspectRatio)
angle += step
points.append(p)
canvas.create_oval(xcenter - radius, ycenter - radius,
xcenter + radius, ycenter + radius)
for i in range(MAXPTS):
for j in range(i, MAXPTS):
canvas.create_line(points[i].x, points[i].y, points[j].x,points[j].y) canvas.pack()
mainloop() if __name__ == '__main__':
LineToDemo()

66、输入3个数a,b,c,按大小顺序输出。

#python3.7

if __name__ == '__main__':
n1 = int(input('n1 = \n'))
n2 = int(input('n2 = \n'))
n3 = int(input('n3 = \n')) def swap(p1, p2):
return p2, p1 if n1 > n2: n1, n2 = swap(n1, n2)
if n1 > n2: n1, n3 = swap(n1, n3)
if n2 > n3: n2, n3 = swap(n2, n3) print(n1, n2, n3)

参考资料:

Python 100例

Python练手例子(11)的更多相关文章

  1. Python练手例子(4)

    16.一个数如果恰好等于它的因子之和,这个数就称为"完数".例如6=1+2+3.编程找出1000以内的所有完数. 程序分析:请参照程序Python 100例中的第14个例子 #py ...

  2. Python练手例子(3)

    13.打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身.例如:153是一个"水仙花数",因为153=1 ...

  3. Python练手例子(10)

    55.学习使用按位取反~. 程序分析:~0=1; ~1=0; (1)先使a右移4位. (2)设置一个低4位全为1,其余全为0的数.可用~(~0<<4) (3)将上面二者进行&运算. ...

  4. Python练手例子(7)

    37.对10个数进行排序. 程序分析:可以利用选择法,即从后9个比较过程中,选择一个最小的与第一个元素交换,下次类推,即用第二个元素与后8个进行比较,并进行交换. #python 3.7 if __n ...

  5. Python练手例子(2)

    7.将一个列表的数据复制到另一个列表中. 程序分析:使用列表[:]. #python3.7 #适用于简单列表(即列表中都是基本的元素) a1 = [1,2] b1 = a1[:] print(b1) ...

  6. Python练手例子(16)

    91.时间函数举例1. #!/usr/bin/python #coding=utf-8 import time if __name__ == '__main__': #time.time()返回当前的 ...

  7. Python练手例子(15)

    85.输入一个奇数,然后判断最少几个 9 除于该数的结果为整数. 程序分析:999999 / 13 = 76923. #!/usr/bin/python #coding=utf-8 if __name ...

  8. Python练手例子(14)

    79.字符串排序. #python3.7 if __name__ == '__main__': str1 = input('Input string:\n') str2 = input('Input ...

  9. Python练手例子(13)

    73.反向输出一个链表. #python3.7 if __name__ == '__main__': ptr = [] for i in range(5): num = int(input('Plea ...

随机推荐

  1. 01pxc集群的部署

    尽可能的控制pxc集群的规模,pxc集群节点越多,数据同步的速度就越慢 所有pxc节点的硬件配置最好相同,pxc集群数据同步的速度取决于配置最低的节点 Pxc集群只支持innodb引擎 安装pxc集群 ...

  2. windows 下 配置 github

       github   功能介绍 1. 记录多个版本 2.查看历史操作,可以进行版本回退和前进的控制 3. 多端共享代码,自动合成  Github  与  SVN   1.  SVN 版本集中管理,所 ...

  3. UVA1449 Dominating Patterns

    UVA1449 Dominating Patterns 题目描述 有N个由小写字母组成的模式串以及一个文本串T.每个模式串可能会在文本串中出现多次.你需要找出哪些模式串在文本串T中出现的次数最多. 输 ...

  4. requests基本应用

    requests基本功能详解 import requests response = requests.get('https://www.baidu.com') print('type属性:',type ...

  5. Django—Form、ModelForm

    一.Form form.py from django import forms from django.core.exceptions import ValidationError from djan ...

  6. Redis在Linux中安装使用

    一.安装$ wget http://download.redis.io/releases/redis-x.x.x.tar.gz $ tar xzf redis-x.x.x.tar.gz $ cd re ...

  7. SQL对某个字段进行排名

    SELECT ( ) AS rowno, a.badge,a.NAME,a.direct_evaluate_rate,a.view_rate FROM ( SELECT * FROM `hrs_sta ...

  8. golang 实现广度优先算法(走迷宫)

    maze.go package main import ( "fmt" "os" ) /** * 广度优先算法 */ /** * 从文件中读取数据 */ fun ...

  9. xcode升级10

    ld: library not found for -lstdc++.6 删除 libstdc++ stackoverflow Building with libstdc++ was deprecat ...

  10. Anaconda的安装与使用

    1. 安装Anaconda(Command Line) 1.1 下载 首先去Anaconda官网查看下载链接,然后通过命令行下载: $ wget https://repo.anaconda.com/a ...