#定义长方形、三角形、圆形的面积计算方法
def changfangxing(a,b): #长和宽
s=a*b #长乘以宽 得到面积
return s
def sanjiaoxing(d,h):
s=(d*h)/2
return s
def yuanxing(r):
s=2*3.14*r
return s
# 函数赋值 接受用户输入数据
a = int(input('请输入长方形的长'))
b = int(input('请输入长方形的宽'))
cfx = changfangxing(a,b)
sjx = sanjiaoxing(2,5)
yx = yuanxing(4)
print ('长方形的面积是%f'%cfx)
print ('三角形的面积是%f'%sjx)
print ('圆形的面积是%f'%yx)
: # Output result
请输入长方形的长4 请输入长方形的宽4 长方形的面积是16.000000 三角形的面积是5.000000 圆形的面积是25.120000 看效果:![]()
Python’s two random numbers add up
import random #引入随机数的模块
# 产生两个随机整数(0-9)
number1 = random.randint(0, 9)
number2 = random.randint(0, 9)
# 输入答案
answer = eval(input("What is " + str(number1) + " + "
+ str(number2) + "? "))
# 显示结果
print(number1, "+", number2, "=", answer,
"is", number1 + number2 == answer)
未经允许不得转载:萌萌Apprentissage » Python introductory example simply calculates the area and simple calculation of rectangular and triangles and circles
Python batches to extract mainstream search engine pictures
Python's word crawling across 100 degrees.
PythonTaiichi Taipei Artificial Intelligence Tensoflow Graphic Processing
Selenium with Tor Browser using Python
I'm gonna get you a new one, shell.cloud.google on the line.
run crontab with python selenium tor browser display in linux