Python input and output exercises, arithmetic exercises, turtle preliminary exercises

Source: Internet
Author: User
Tags arithmetic for in range

  • Hello world!
  • Simple Interactive (interactive, file-style) textbook P19
  • radius=25Area =3.1415*radius*radiusprint('  {:. 2f} '. Format (area)

  • The user enters two numbers and calculates and outputs the sum of two digits:
  • A=input (' Please enter the first number:') b=input (" Please enter the second number:") C =float (a) +float (b)print(' two of sum:')Print (c)
  • The user enters the triangular three-side length and calculates the area of the triangle: (Helen Formula)
  •  while1==1: A=float (Input ('Please enter the first edge of the triangle: \ n')) b=float (Input ('Please enter the second edge of the triangle: \ n')) C=float (Input ('Please enter the third side of the triangle: \ n'))    if(A+B&GT;C) and(A+C&GT;B) and(B+c>a) andABS ((a) <c) andABS ((A-C) <b) andABS ((B-C) <a): Break        Else:        Print('input wrong, please re-enter! \ n') P=float ((a+b+c)/2) s=float (p* (p-a) * (p-b) * (p-c)) **0.5Print('area of%.2f'%S

  • Enter a radius to calculate the area of the circle.
  • # r=float (Input (' Please enter radius of circle: ')) Print (' area:', 3.1415*float (Input (' Please enter radius of circle:') ') **2)

  • Draw a set of identical tangent circles
  • Import turtleturtle.circle (turtle.circle)turtle.circle(+)turtle.circle ( 100)

  • Draw a Pentagram
  • Import Turtle  for  in range (5):    turtle.forward (+)    Turtle.left (144)
  • Draw an all-yellow pentagram
  • Import turtleturtle.shape ('turtle') turtle.speed()Turtle.color ( ' yellow') turtle.fillcolor ('yellow' ) ) Turtle.begin_fill () for in range (5):    turtle.forward (+)    Turtle.left (144) Turtle.end_fill ()

  • Thinking
  • Draw a set of concentric circles.
  • Import turtleturtle.speed (turtle.penup) turtle.goto (0,+) Turtle.pendown () turtle.circle ( Turtle.penup () turtle.goto (0)turtle.pendown () turtle.circle ()turtle.penup () Turtle.goto (0,turtle.pendown) turtle.circle ()turtle.penup () turtle.goto (0,+) Turtle.pendown () turtle.circle (70)

  • Draw five pentagram on the national flag.
ImportTurtleturtle.speed (41) Turtle.penup () Turtle.goto (-300,240) Turtle.pendown ()##画国旗背景Turtle.fillcolor ('Red') Turtle.begin_fill () Turtle.forward (600) Turtle.right (90) Turtle.forward (400) Turtle.right (90) Turtle.forward (600) Turtle.right (90) Turtle.forward (400) Turtle.end_fill ()##画大五角星Turtle.penup () Turtle.goto (-263,163) Turtle.pendown () Turtle.color ('Yellow') Turtle.fillcolor ('Yellow') Turtle.begin_fill () Turtle.right (90) forIinchRange (5): Turtle.forward (100) Turtle.right (144) Turtle.end_fill ()##画小五角星##第一个Turtle.penup () Turtle.goto (-126,211) Turtle.pendown () Turtle.color ('Yellow') Turtle.fillcolor ('Yellow') Turtle.begin_fill () Turtle.right (90) forIinchRange (5): Turtle.forward (20) Turtle.right (144) Turtle.end_fill ()##第二个Turtle.penup () Turtle.goto (-100,160) Turtle.pendown () Turtle.color ('Yellow') Turtle.fillcolor ('Yellow') Turtle.begin_fill () Turtle.right (90) forIinchRange (5): Turtle.forward (20) Turtle.right (144) Turtle.end_fill ()##第三个Turtle.penup () Turtle.goto (-107,116) Turtle.pendown () Turtle.color ('Yellow') Turtle.fillcolor ('Yellow') Turtle.begin_fill () Turtle.right (90) forIinchRange (5): Turtle.forward (20) Turtle.right (144) Turtle.end_fill ()##第四个Turtle.penup () Turtle.goto (-133,95) Turtle.pendown () Turtle.color ('Yellow') Turtle.fillcolor ('Yellow') Turtle.begin_fill () Turtle.right (90) forIinchRange (5): Turtle.forward (20) Turtle.right (144) Turtle.end_fill ()

Python input and output exercises, arithmetic exercises, turtle preliminary exercises

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.