Python applet exercises (7) September 28, 2017---Tell yourself how to practice, not to dream.

Source: Internet
Author: User
Tags abs for in range

1. String Stitching Program

STR1 = input (" Please enter a name for a person:"= input (" Enter a country name:")  Print("The world is so big, {} want to see {}.")  ". Format (STR1,STR2))

2, Integer series summation

n = input (" Please enter integer n:"= 0 for in range (int (n)):    +=i+1Print("1 to N summation result:", sum)

3, 99 multiplication table neat output

 for  in range (1,10):    is in range (i,i+1):         print("  {}*{}={:2}". Format (j,i,i*j), end=")    print( ")

4, factorial calculation, calculation 1+2!+.....+10! The results

SUM, TMP = 0,1 for in range (1,11):    tmp*=i    sum+ =tmpPrint (the result of the operation is: {}. Format (SUM))

5, the monkey eat peach problem . The monkey picked a few peaches on the first day, ate half of it, but became addicted, ate one more, ate half the remaining peaches in the morning and ate one more. Every morning after eating the day before the rest of the more than half one. when I want to eat again in the morning of the fifth day, I see only one peach left. Please write a program to calculate How many peaches the monkeys picked up on the first day.

N=1 for in range (5,0,-1= (n+1) <<1print(n)

6, Healthy recipes output. List of 5 different ingredients, please print out what they may consist of There is a dish name.

Diet = ['Tomato','Broccoli','Cucumber','Steak','Shrimp'] forXinchRange (0,5): forYinchRange (0,5):if  not(x==y):Print("{}{}". Format (Diet[x],diet[y]))

7. The drawing of the pentagram. draw a red pentagram graphic.

 from Import*fillcolor ("red") Begin_fill () while True:    Forward (+) Right    (144)    if abs (POS ()) <1:          Break End_fill ()

8, the Sun flower drawing. draw a graph of the sun flower.

 from Import*color ('red','yellow') begin_ Fill () while True:    forward ($) left    (     in) If abs (POS ()) <1:        breakEnd_fill () done ()

9, the drawing of the helix. draws a graphic of a spiral.

Import Turtle Import timeturtle.speed ("fastest") turtle.pensize (2)  for  in range:    turtle.forward (x)    turtle.left (time.sleep) ( 3)

10, the color spiral drawing. Code has a problem, only black background, no brushes

ImportTurtleImportTimeturtle.pensize (2) Turtle.bgcolor ("Black") Colors= ["Red","Yellow","Purple","Blue"]turtle.tracer (False) forXinchRange (400): Turtle.forward (*x) turtle.color (color[x%4]) Turtle.left (91) Turtle.tracer (True)

Python applet exercises (7) September 28, 2017---Tell yourself how to practice, not to dream.

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.