Python起航



#海龟画圆圈
#number_4.py
import turtle
colors = [‘purple‘]
t = turtle.Pen()
turtle.bgcolor(‘yellow‘)
for x in range(300):
    #t.pencolor(colors[x%6])
    #t.width(x/100 + 1)
    t.circle(x)
    t.left(91)

#绘制旋转七彩图#number_1.py
import turtle
colors = [‘red‘, ‘purple‘, ‘blue‘, ‘green‘, ‘yellow‘, ‘orange‘]
t = turtle.Pen()
turtle.bgcolor(‘black‘)
for x in range(360):
    t.pencolor(colors[x%6])
    t.width(x/100 + 1)
    t.forward(x)
    t.left(59)
#输入名字输出名字
#Helloworld.py
name = input("What‘s your name?\n")
print("Hello ,",name)
#眩晕图来也~~~
#number_3.py
import turtle
colors = [‘purple‘]
t = turtle.Pen()
turtle.bgcolor(‘yellow‘)
for x in range(300):
    #t.pencolor(colors[x%6])
    #t.width(x/100 + 1)
    t.forward(x)
    t.left(90)#旋转度数
#Python绘图大法!!!
#number_5 一个变量搞定一切.py
import turtle
colors = [‘yellow‘, ‘red‘, ‘purple‘, ‘green‘, ‘blue‘, ‘orange‘]
sides = eval(input("Enter a number between 2 and 6: "))
t = turtle.Pen()
turtle.bgcolor(‘black‘)
for x in range(360):
    t.pencolor(colors[x % sides])
    t.width(x * sides/200)
    t.forward(x * 3/sides + x)
    t.left(360/sides + 20)
#number_7 螺旋式输出名字.py
import turtle
t = turtle.Pen()
turtle.bgcolor(‘black‘)
colors = [‘red‘, ‘purple‘, ‘blue‘, ‘orange‘]
name = turtle.textinput("Please enter your name", "What‘s your name?")
for x in range(100):
    t.pencolor(colors[x % 4])
    t.penup()
    #t.width(x * sides/200)
    t.forward(x * 4)
    t.pendown()
    t.write(name, font = ("Arial", int((x+4)/4),"bold"))
    t.left(93)
#random函数和坐标
import random
import turtle
t = turtle.Pen()
turtle.bgcolor("black")
colors = ["red", "yellow", "blue", "green", "orange", "purple", "white", "gray"]
for n in range(50):
    t.pencolor(random.choice(colors))
    size = random.randint(10, 40)
    x = random.randrange(-turtle.window_width()//2,
                          turtle.window_width()//2)
    y = random.randrange(-turtle.window_height()//2,
                          turtle.window_height()//2)
    t.penup()
    t.setpos(x,y)
    t.pendown()
    for m in range(size):
        t.forward(m * 2)
        t.left(95)
#Rock_Paper_Scissors
#RockPaperScissors.py
import random
choices = ["rock", "paper", "scissors"]
print("Rock crushes scissors. Scissors cut paper. Paper covers rock.")
player = input("Do you want to be rock, paper, or scissors (or quit)? ")
while player != "quit":                 # Keep playing until the user quits
    player = player.lower()             # Change user entry to lowercase
    computer = random.choice(choices)   # Pick one of the items in choices
    print("You chose " +player+ ", and the computer chose " +computer+ ".")
    if player == computer:
        print("It‘s a tie!")
    elif player == "rock":
        if computer == "scissors":
            print("You win!")
        else:
            print("Computer wins!")
    elif player == "paper":
        if computer == "rock":
            print("You win!")
        else:
            print("Computer wins!")
    elif player == "scissors":
        if computer == "paper":
            print("You win!")
        else:
            print("Computer wins!")
    else:
        print("I think there was some sort of error...")
    print()                             # Skip a line
    player = input("Do you want to be rock, paper, or scissors (or quit)? ")
#选牌游戏
# HighCard.py
import random
suits = ["clubs", "diamonds", "hearts", "spades"]
faces = ["two", "three", "four", "five", "six", "seven", "eight", "nine",
         "ten", "jack", "queen", "king", "ace"]
keep_going = True
while keep_going:
    my_face = random.choice(faces)
    my_suit = random.choice(suits)
    your_face = random.choice(faces)
    your_suit = random.choice(suits)
    print("I have the", my_face, "of", my_suit)
    print("You have the", your_face, "of", your_suit)
    if faces.index(my_face) > faces.index(your_face):
        print("I win!")
    elif faces.index(my_face) < faces.index(your_face):
        print("You win!")
    else:
        print("It‘s a tie!")
    answer = input("Hit [Enter] to keep going, any key to exit: ")
    keep_going = (answer == "")
#五个骰子
# FiveDice.py
import random
# Game loop
keep_going = True
while keep_going:
    # "Roll" five random dice
    dice = [0,0,0,0,0]          # Set up an array for five values dice[0]-dice[4]
    for i in range(5):          # "Roll" a random number from 1-6 for all 5 dice
        dice[i] = random.randint(1,6)
    print("You rolled:", dice)  # Print out the dice values
    # Sort them
    dice.sort()
    # Check for five of a kind, four of a kind, three of a kind
    # Yahtzee - all five dice are the same
    if dice[0] == dice[4]:
        print("Yahtzee!")
    # FourOfAKind - first four are the same, or last four are the same
    elif (dice[0] == dice[3]) or (dice[1] == dice[4]):
        print("Four of a kind!")
    # ThreeOfAKind - first three, middle three, or last three are the same
    elif (dice[0] == dice[2]) or (dice[1] == dice[3]) or (dice[2] == dice[4]):
        print("Three of a kind")
    keep_going = (input("Hit [Enter] to keep going, any key to exit: ") == "")
#万花筒(很好看很对称!!)
#Kaleidoscope.py
import random
import turtle
t = turtle.Pen()
t.speed(0)
turtle.bgcolor("black")
colors = ["red", "yellow", "blue", "green", "orange", "purple", "white", "gray"]
for n in range(50):
    # Generate spirals of random sizes/colors at random locations on the screen
    t.pencolor(random.choice(colors))   # Pick a random color from colors[]
    size = random.randint(10,40)        # Pick a random spiral size from 10 to 40
    # Generate a random (x,y) location on the screen
    x = random.randrange(0,turtle.window_width()//2)
    y = random.randrange(0,turtle.window_height()//2)
    # First spiral
    t.penup()
    t.setpos(x,y)
    t.pendown()
    for m in range(size):
        t.forward(m*2)
        t.left(91)
    # Second spiral
    t.penup()
    t.setpos(-x,y)
    t.pendown()
    for m in range(size):
        t.forward(m*2)
        t.left(91)
    # Third spiral
    t.penup()
    t.setpos(-x,-y)
    t.pendown()
    for m in range(size):
        t.forward(m*2)
        t.left(91)
    # Fourth spiral
    t.penup()
    t.setpos(x,-y)
    t.pendown()
    for m in range(size):
        t.forward(m*2)
        t.left(91)
时间: 2024-12-07 22:29:41

Python起航的相关文章

Python 从入门到升职加薪

(课程结构图) 据小伙伴们的反馈,传统运维大多处于面临转型的状态.想要转运维开发,那就推荐大家一把利器-- Python 语言. Python 实战班 适合人群 想往开发或者运维开发方向发展,Python 基础为零或薄弱,但能读懂shell 或者其它任何一门语言的同学 课程目标 学员熟练掌握 Python 基础,能够通过 Python 完成日常项目的开发,能将处理的数据进行浏览器端可视化展示,能够独立完成精简版 CMDB 和快速构建单机版监控系统 上课模式 支持面授班与网络实时直播班(Reboo

【转】windows下python开发环境搭建

1 -- 安装python的前期准备 Python开发有众多工具,又以Eclipse+Pydev最为常见.Eclipse平台对开发同学来讲,肯定是如雷贯耳,自不用废话.而PyDev是Eclipse平台下的一个Python IDE插件,利用PyDev插件我们可以把Eclipse变为功能强大且易用的Python IDE.本文只简单介绍Eclipse+PyDev的安装和配置过程,至于开发.调试等高级话题不做深入分析. 首先,需要安装python的编译和执行程序,推荐安装Python2.7.3版本.至于

python基于函数替换的热更新原理介绍

热更新即在不重启进程或者不离开Python interpreter的情况下使得被编辑之后的python源码能够直接生效并按照预期被执行新代码.平常开发中,热更能极大提高程序开发和调试的效率,在修复线上bug中更是扮演重要的角色.但是要想实现一个理想可靠的热更模块又非常的困难. 1.基于reload reload作为python官方提供的module更新方式,有一定作用,但是很大程度上并不能满足热更的需求. 先来看一下下面的问题: >>> import sys, math >>

SQLite3 of python

SQLite3 of python 一.SQLite3 数据库 SQLite3 可使用 sqlite3 模块与 Python 进行集成,一般 python 2.5 以上版本默认自带了sqlite3模块,因此不需要用户另外下载. 在 学习基本语法之前先来了解一下数据库是使用流程吧 ↓↓↓ 所以,首先要创建一个数据库的连接对象,即connection对象,语法如下: sqlite3.connect(database [,timeout,其他可选参数]) function: 此API打开与SQLite

Python学习1-Python和Pycharm的下载与安装

本文主要介绍Python的下载安装和Python编辑器Pycharm的下载与安装. 一.Python的下载与安装 1.下载 到Python官网上下载Python的安装文件,进入网站后显示如下图: 网速访问慢的话可直接在这里下载:python-2.7.11.amd64 在Downloads中有对应的支持的平台,这里我们是在Windows平台下运行,所以点击Windows,出现如下: 在这里显示了Python更新的所有版本,其中最上面两行分别是Python2.X和Python3.X对应的最后更新版本

Python——深入理解urllib、urllib2及requests(requests不建议使用?)

深入理解urllib.urllib2及requests            python Python 是一种面向对象.解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年,Python 源代码同样遵循 GPL(GNU General Public License)协议[1] .Python语法简洁而清晰,具有丰富和强大的类库. urllib and urllib2 区别 urllib和urllib2模块都做与请求URL相关的操作,但

python学习_day26_面向对象之封装

1.私有属性 (1)动态属性 在python中用双下划线开头的方式将属性隐藏起来.类中所有双下划线开头的名称,如__x都会自动变形成:_类名__x的形式.这种自动变形的特点是: a.类中定义的__x只能在内部使用,如self.__x,引用的就是变形的结果.b.这种变形其实正是针对外部的变形,在外部是无法通过__x这个名字访问到的.c.在子类定义的__x不会覆盖在父类定义的__x,因为子类中变形成了:_子类名__x,而父类中变形成了:_父类名__x,即双下滑线开头的属性在继承给子类时,子类是无法覆

python面向对象知识点疏理

面向对象技术简介 类: 用来描述具有相同的属性和方法的对象的集合.它定义了该集合中每个对象所共有的属性和方法.对象是类的实例.class 类变量:类变量在整个实例化的对象中是公用的.类变量定义在类中且在函数体之外.类变量通常不作为实例变量使用. 数据成员:类变量或者实例变量用于处理类及其实例对象的相关的数据. 方法重写:如果从父类继承的方法不能满足子类的需求,可以对其进行改写,这个过程叫方法的覆盖,也称为方法的重写. 实例变量:定义在方法中的变量,只作用于当前实例的类. 继承:即一个派生类(de

python实现网页登录时的rsa加密流程

对某些网站的登录包进行抓包时发现,客户端对用户名进行了加密,然后传给服务器进行校验. 使用chrome调试功能断点调试,发现网站用javascript对用户名做了rsa加密. 为了实现网站的自动登录,需要模拟这个加密过程. 网上搜了下关于rsa加密的最简明的解释: rsa加密是非对称加密算法,该算法基于一个十分简单的数论事实:将两个大素数相乘十分容易,但那时想要对其乘积进行因式分解却极其困难,因此可以将乘积公开作为加密密钥,即公钥,而两个大素数组合成私钥.公钥是可发布的供任何人使用,私钥则为自己