Instructor song Tian's zero base Python notes: https://www.bilibili.com/video/av15123607? From = search & amp; seid = 10211084839195730432 #35-37 in page = 25,

Source: Internet
Author: User

Instructor song Tian's zero base Python notes: https://www.bilibili.com/video/av15123607? From = search & seid = 10211084839195730432 #35-37 in page = 25,

# Coding = gbk
# Instructor song Tian's zero-based Python Note: https://www.bilibili.com/video/av15123607? From = search & seid = 10211084839195730432 #35-37 in page = 25
# Procedure for processing multiple bank accounts
"""
Def addInterest (balances, rate ):
For I in range (len (balances )):
Balances [I] = balances [I] * (1 + rate)

Def test ():
Amounts = [1000,105,350 0, 739]
Print (id (amounts) # Real parameter amounts memory address
Rate = 0.05
AddInterest (amounts, rate) # The real parameter amounts changes when calling the function.
Print (id (amounts) # The real parameter amounts memory address has not changed
Print (amounts)
Amounts. append (700)
Print (id (amounts) # The real parameter amounts memory address has not changed
Print (amounts)

Test ()
"""
# Examples of program modularization
# Program 1:
"""
Print ("This program plots the growth of a 10-year investigation .")
Principal = eval (input ("Enter the initial principal :"))
Apr = eval (input ("Enter the annualized interest rate :"))
For year in range (1, 11 ):
Principal = principal * (1 + apr)
Print ("% 2d" % year, end = '')
Total = int (principal * 4/1000)
Print ("*" * total)
Print ("0.0 K 2.5 K 5.0 K 7.5 K 10.0 K ")
"""

# Modularize program 1
"""
Def creatTable (principal, apr ):
For year in range (1, 11 ):
Principal = principal * (1 + apr)
Print ("% 2d" % year, end = '')
Total = caculateNum (principal)
Print ("*" * total)
Print ("0.0 K 2.5 K 5.0 K 7.5 K 10.0 K ")

Def caculateNum (principal ):
Total = int (principal * 4/1000)
Return total

Def main ():
Print ("This program plots the growth of a 10-year investigation .")
Principal = eval (input ("Enter the initial principal :"))
Apr = eval (input ("Enter the annualized interest rate :"))
CreatTable (principal, apr)

Main ()
"""
# Python parameters are passed through values
# If the variable is a mutable object, after returning to the calling program, the object will be in the modified state.

# Features defined by recursion:
# One or more base instances do not need to be recursive again
# All recursive links must end with a base example
# Recursion each call will cause the start of a new function
# Recursion has a copy of the local value, including the parameter of this value
# In a factorial recursive function, the relevant n values in each function call are temporarily stored in the intermediate recursive chain and used when the function is returned.

# Recurrence function of factorial:
"""
Def fact (n ):
If n = 0:
Return 1
Else:
Return n * fact (n-1)
"""
# String inversion recursion Function
Def reverse (s ):
If s = "":
Return s
Else:
Return reverse (s [1:]) + s [0]
Print (reverse ("iloveyou "))
#
# Common commands of the turtle Database
# Forward (distance) Move the arrow to a specified Coordinate
# Left (angel) right (angel)
# Penup () is used to draw a pen in another place and paired with pendown.
# Goto (x, y)
# Home ()
# Circle (radius)
# Speed ()
#
# Use the turtle library to draw and fill in a five-star program
"""
From turtle import Turtle

P = Turtle ()
P. speed (1)
P. pensize (5)
P. color ("black", "yellow ")
P. begin_fill ()
For I in range (5 ):
P. forward (200)
P.right (144)
P. end_fill ()
"""
# Draw a tree using recursive functions:
From turtle import Turtle

Def maketree (x, y ):
P = Turtle ()
P. speed (0.1)
P. color ("green ")
P. pensize (5)
P. hideturtle ()
P. getscreen (). tracer (30,0)
P. left (90)
P. penup ()
P. goto (x, y)
P. pendown ()
T = tree ([p], 110,65, 0.6375)
Print (len (p. getscreen (). turtles () # How many turtle images are used

Def tree (plist, l, a, f ):
If l> 5:
Lst = []
For p in plist:
P. forward (l)
Q = p. clone ()
P. left ()
Q. right ()
Lst. append (p)
Lst. append (q)
Tree (lst, l * f, a, f)

Def main ():
Maketree (-1, 200,200)
Maketree (0, 0)
Maketree (200,-200)

Main ()

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.