标签:world blog input 公式 break style first bsp pos
1、Hello World!
print("Hello World!")
2、简单交互(交互式,文件式)教材P19
>>> name = input("please input your name:") >>> please input your name:Poon >>> print(name) >>> Poon
3、用户输入两个数字,计算并输出两个数字之和:
s1 = float(input("please input the first num:")) s2 = float(input("please input the second num:")) sum = s1 + s2 print("the result is:%s" % sum) print("the result is %.2f" %((float(input("the first num is"))) + (float(input("the secibd num is")))))
4、用户输入三角形三边长度,并计算三角形的面积:(海伦公式)
a = float(input("Please input the a side:")) b = float(input("Please input the b side:")) c = float(input("Please input the c side:")) p = (a + b + c)/2 s = (p *(p-a) *(p-b)*(p-c))**0.5 print("the square is:%.2f" % s)
5、输入半径,计算圆的面积。
from math import pi r = float(input("Please input the r:")) s = pi * (r**2) print("the area is %.2f" % s)
6、画一组同切圆
import turtle as t t.speed(1) t.circle(10) t.circle(20) t.circle(30)
7、画一个五角星
import turtle as t t.speed(1) for i in range(5): t.forward(100)
t.right(144)
8、画一个全黄色的五角星
import turtle as t t.fillcolor("red") t.begin_fill() while True: t.forward(200) t.right(144) if abs(pos())<1: break t.end_fill()
标签:world blog input 公式 break style first bsp pos
原文地址:http://www.cnblogs.com/poonxiujet/p/7483927.html