• 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?
    ")
    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)
  • 相关阅读:
    MFC程序执行过程剖析
    不同位数操作系统的 数据长度
    测试:safenet提供的CheckKey函数 内存泄漏。具体来说是句柄.
    关于更改项目名称
    内存泄漏相关的
    美化MFC 之调整静态文本的颜色 字体。 用于添加公司标题 联系方式 口号等数据
    DAVINCI DM365-DM368开发攻略——开发环境搭建(DVSDK4.02)
    Removing Unnecessary HTTP Headers in IIS and ASP.NET 在ASP.Net和IIS中删除不必要的HTTP响应头
    Implementing Singleton in C#
    WEBAPI VS WCF微软随.NET 4.5发布新REST API框架
  • 原文地址:https://www.cnblogs.com/6666junyiliu/p/6044111.html
Copyright © 2020-2023  润新知