zoukankan      html  css  js  c++  java
  • Python输入输出练习,运算练习,turtle初步练习

    1、Hello World!

    1 print("Hello World!")

    2、用户输入两个数字,计算并输出两个数字之和:

    用户输入三角形三边长度,并计算三角形的面积:(海伦公式)

    输入半径,计算圆的面积。

     1 import math
     2 
     3 def xixi(num1,num2):
     4     return print("
    和为:" , float(num1)+float(num2))
     5 
     6 def sjxmianji(a,b,c):
     7     a = float(a)
     8     b = float(b)
     9     c = float(c)
    10     if a<0 && b<0 &&c<0:
    11         return print("请输入正数!")
    12     elif a+b<c && a+c<b && b+c<a:
    13         return print("两边之和不能小于第三边!")
    14     else:
    15         s=(a + b + c)/2
    16         S=math.sqrt(s*(s-a)*(s-b)*(s-c))
    17         return print("
    三角形的面积为:" , S)
    18 
    19 def yuanmianji(r):
    20     pai =3.14
    21     R = float(r)
    22     S = pai * R * R
    23     return print("
    园的面积为:" , S)
    24 
    25 print("
    1、计算两数之和")
    26 num1 = input("请输入第一个数字:")
    27 num2 = input("请输入第二个数字:")
    28 xixi(num1,num2)
    29 
    30 print("
    2、计算三角形面积")
    31 a = input("请输入第一条边的长度:")
    32 b = input("请输入第二条边的长度:")
    33 c = input("请输入第三条边的长度:")
    34 sjxmianji(a,b,c)
    35 
    36 print("
    1、计算园的面积")
    37 r = input("请输入园的半径:")
    38 yuanmianji(r)

    输出结果:

     1 1、计算两数之和
     2 请输入第一个数字:60
     3 请输入第二个数字:99
     4 
     5 和为: 159.0
     6 
     7 2、计算三角形面积
     8 请输入第一条边的长度:6
     9 请输入第二条边的长度:7
    10 请输入第三条边的长度:8
    11 
    12 三角形的面积为: 20.33316256758894
    13 
    14 1、计算园的面积
    15 请输入园的半径:6
    16 
    17 园的面积为: 113.03999999999999

    3、画一组同切圆

    1 turtle.circle(10)
    2 turtle.circle(20)
    3 turtle.circle(40)
    4 turtle.circle(60)

    输出结果:

    4、画一个五角星

    1 turtle.forward(200)
    2 turtle.right(144)
    3 turtle.forward(200)
    4 turtle.right(144)
    5 turtle.forward(200)
    6 turtle.right(144)
    7 turtle.forward(200)
    8 turtle.right(144)
    9 turtle.forward(200)

    输出结果:

    5、画一个全黄色的五角星

     1 turtle.right(20)
     2 turtle.color('yellow')
     3 turtle.fillcolor('yellow')
     4 turtle.begin_fill()
     5 turtle.forward(80)
     6 turtle.right(144)
     7 turtle.forward(80)
     8 turtle.right(144)
     9 turtle.forward(80)
    10 turtle.right(144)
    11 turtle.forward(80)
    12 turtle.right(144)
    13 turtle.forward(80)
    14 turtle.end_fill()

    输出结果:

    6、画一组同心圆

    1 for i in range(4):
    2     turtle.pu()
    3     turtle.goto(0,-(i+1)*10)
    4     turtle.pd()
    5     turtle.circle((i+1)*10)

    输出结果:

    7、画一面五星红旗

     1 turtle.speed(10)
     2 turtle.color('red')
     3 turtle.fillcolor('red')
     4 turtle.pu()
     5 turtle.goto(-300,200)
     6 turtle.pd()
     7 turtle.begin_fill()
     8 turtle.forward(500)
     9 turtle.right(90)
    10 turtle.forward(300)
    11 turtle.right(90)
    12 turtle.forward(500)
    13 turtle.right(90)
    14 turtle.forward(300)
    15 turtle.end_fill()
    16 
    17 turtle.goto(-250,60)
    18 turtle.right(20)
    19 turtle.color('yellow')
    20 turtle.fillcolor('yellow')
    21 turtle.begin_fill()
    22 turtle.forward(80)
    23 turtle.right(144)
    24 turtle.forward(80)
    25 turtle.right(144)
    26 turtle.forward(80)
    27 turtle.right(144)
    28 turtle.forward(80)
    29 turtle.right(144)
    30 turtle.forward(80)
    31 turtle.end_fill()
    32 
    33 turtle.pu()
    34 turtle.goto(-140,170)
    35 turtle.pd()
    36 turtle.begin_fill()
    37 turtle.forward(30)
    38 turtle.right(144)
    39 turtle.forward(30)
    40 turtle.right(144)
    41 turtle.forward(30)
    42 turtle.right(144)
    43 turtle.forward(30)
    44 turtle.right(144)
    45 turtle.forward(30)
    46 turtle.end_fill()
    47 
    48 turtle.pu()
    49 turtle.goto(-110,130)
    50 turtle.pd()
    51 turtle.begin_fill()
    52 turtle.forward(30)
    53 turtle.right(144)
    54 turtle.forward(30)
    55 turtle.right(144)
    56 turtle.forward(30)
    57 turtle.right(144)
    58 turtle.forward(30)
    59 turtle.right(144)
    60 turtle.forward(30)
    61 turtle.end_fill()
    62 
    63 turtle.pu()
    64 turtle.goto(-110,50)
    65 turtle.pd()
    66 turtle.begin_fill()
    67 turtle.forward(30)
    68 turtle.right(144)
    69 turtle.forward(30)
    70 turtle.right(144)
    71 turtle.forward(30)
    72 turtle.right(144)
    73 turtle.forward(30)
    74 turtle.right(144)
    75 turtle.forward(30)
    76 turtle.end_fill()
    77 
    78 turtle.pu()
    79 turtle.goto(-160,30)
    80 turtle.pd()
    81 turtle.begin_fill()
    82 turtle.forward(30)
    83 turtle.right(144)
    84 turtle.forward(30)
    85 turtle.right(144)
    86 turtle.forward(30)
    87 turtle.right(144)
    88 turtle.forward(30)
    89 turtle.right(144)
    90 turtle.forward(30)
    91 turtle.end_fill()
    View Code

    输出结果:

  • 相关阅读:
    Java学习心得16
    Java学习心得15
    Java学习心得14
    Java学习心得13
    Java学习心得12
    Java学习心得11
    Java学习心得10
    Java学习心得09
    Java学习心得08
    JVM垃圾回收
  • 原文地址:https://www.cnblogs.com/xypbk/p/7483971.html
Copyright © 2011-2022 走看看