Python language program @ bulk heaven, yellow heaven feather, courtesy
n = input("Import N:")
sum = 0
for i in range(int(n)):
sum += i + 1
print("1 to N summation result:",sum)
for i in range(1,10):
for j in range(1,i+1):
print("{}*{}={:2}".format(j,i,i*j),end=' ')
print(' ')
import turtle
import time
turtle.pensize(2)
turtle.bgcolor("black")
colors = ["red","yellow","purple","blue"]
turtle.tracer(False)
for x in range(400):
turtle.forward(2*x)
turtle.color(colors[x % 4])
turtle.left(91)
turtle.tracer(True)
Export:
val = input("please input the temprature(eg:32C):")
if val[-1] in ['C','c']:
f = 1.8 * float(val[0:-1]) + 32
print("after the conversion: %.2fF"%f)
elif val[-1] in ['F','f']:
c = (float(val[0:-1]) - 32) / 1.8
print("after the conversion: %.2fC"%c)
else:
print("input error!!")
>>> t="abcdefg"
>>> t[3]
'd'
>>> t[-3]
'e'
>>> t[1:3]
'bc'
>>> t[1:-3]
'bcd'
>>> "python" + ":" + t[0:3]
'python:abc'
Top-level program analysis:
#Piecewise piecewise color painting
import turtle
def drawSnake(rad,angle,len,neckrad):
for i in range(len):
turtle.circle(rad,angle)
if(i%2 == 0):
turtle.pencolor("blue")
else:
turtle.pencolor("red")
turtle.circle(-rad,angle)
turtle.circle(rad,angle/2)
turtle.fd(rd)
turtle.circle(neckrad+1,180)
turtle.fd(rad*2/3)
def main():
turtle.setup(1300,800,0,0)
pythonsize = 30
turtle.pensize(pythonsize)
turtle.seth(-40)
drawSnake(40,80,5,pythonsize/2)
main()
from turtle import *
, can be used directly, the common function XX ()#Drawing triangle
import turtle
def main():
turtle.setup(1300,800,0,0)
pythonsize = 2
turtle.pensize(pythonsize)
turtle.seth(0)
turtle.fd(90)
turtle.seth(120)
turtle.fd(90)
turtle.seth(240)
turtle.fd(90)
main()
Main explanations of this book 6 types of Python typology:
--Numeric character string type --Former group column type --Sentence type dictionary type
sum
sys.float_info`, pre-determination accuracy:print ("\" hello \ "")
Export:" hello ".#General character string Kushibuki eradication line export
str="hell,world"
for i in str:
print(i + "\n")
print("end")
>>> print("Hello\nWorld\n")
Hello
World
Immutable object, more safe
** Original concept: **
** Original features: **
** Column table concept: **
>>> from random import *
>>> seed(2)
>>> uniform(1,10)
9.604308447003245
>>> uniform(1,10)
9.530447383534144
>>> uniform(1,10)
1.5089623095412783
>>> seed(2)
>>> uniform(1,10)
9.604308447003245
>>> uniform(1,10)
9.530447383534144
>>> uniform(1,10)
1.5089623095412783
After the top surface has been set up, the number of random numbers will be randomized. Calculator Calculator Calculator, Impossible generation Authentic random number, Random number of Random numbers, Random number of seeds. Random seeds, seed () function, randomness, and system.
Pi irrational number, irrational formula can be calculated, PI-like calculation, approximate calculation method. Unit squares for all types of squares, large number of points, opposite points, possible inside or outside, the number of points that can be reached to a certain extent, the area of the area, the area of the area, the area of the area, the area of the area, the area of the area, and the area of the area. 圆 Inner score excluding 圆 Outer score ratio, immediate π / 4. The number of random points is large, and the pi is perfect.
from random import random
from math import sqrt
from time import clock
DARTS = 1200000
hits = 0
clock()
for i in range(1,DARTS):
x,y = random(),random()
dist = sqrt(x**2 + y**2)
if dist <=1.0:
hits = hits + 1
pi = 4 *(hits/DARTS)
print("pi-like%s"%pi)
print("Program time%-5.5ss"%clock())
Export consequences:
pi-like slogan 3.14148 Program time 2.655s
Caution:
x, y = random (), random ()
, can 给 赋 值.x, y = y, x
Analysis example:
Recommended Posts