Python输入输出练习,运算练习,turtle初步练习
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python输入输出练习,运算练习,turtle初步练习相关的知识,希望对你有一定的参考价值。
- Hello World!
-
print("Hello World!!")
-
- 简单交互(交互式,文件式)教材P19
-
name=input("what is your name?\n") where=input("where are you now?\n") age=input("how old are you ?\n") print("your name is {}".format(name)) print("you live in {}".format(where)) print("you are {} years old".format(age))
-
- 用户输入两个数字,计算并输出两个数字之和:
-
num1=input("input a number:\n") num2=input("input an other number:\n") print(sum,end="") sum=num1+num2
-
- 用户输入三角形三边长度,并计算三角形的面积:(海伦公式)
-
a = float(input("输入第一边边长:")) b = float(input("输入第二边边长:")) c = float(input("输入第三边边长:")) s = (a + b + c) / 2 area = (s*(s-a)*(s-b)*(s-c)) ** 0.5 print("三角形面积为 %0.2f" %area)
- 输入半径,计算圆的面积。
pi=3.1415926 r=float(input("请输入半径:")) area=pi*r*r print("面积为 %0.2f"%area)
- 画一组同切圆
import turtle turtle.speed(100) turtle.circle(10) turtle.circle(20) turtle.circle(30) turtle.circle(40)
- 画一个五角星
import turtle turtle.speed(100) turtle.forward(100) turtle.right(144) turtle.forward(100) turtle.right(144) turtle.forward(100) turtle.right(144) turtle.forward(100) turtle.right(144) turtle.forward(100) turtle.right(144)
- 画一个全黄色的五角星
import turtle turtle.speed(100) turtle.fillcolor("yellow") turtle.begin_fill() turtle.forward(100) turtle.right(144) turtle.forward(100) turtle.right(144) turtle.forward(100) turtle.right(144) turtle.forward(100) turtle.right(144) turtle.forward(100) turtle.right(144) turtle.end_fill()
思考:
- 画一组同心圆。
import turtle #draw first circle turtle.penup() turtle.goto(0,-200) turtle.pendown() turtle.circle(200) #draw second circle turtle.penup() turtle.goto(0,-150) turtle.pendown() turtle.circle(150) #draw third circle turtle.penup() turtle.goto(0,-100) turtle.pendown() turtle.circle(100) #draw fourth circle turtle.penup() turtle.goto(0,-50) turtle.pendown() turtle.circle(50)
- 画国旗上的五个五角星
以上是关于Python输入输出练习,运算练习,turtle初步练习的主要内容,如果未能解决你的问题,请参考以下文章