设计三个菜单,画多边形,画矩形,画椭圆python
时间: 2023-08-15 17:11:20 浏览: 80
以下是基于Python的三个菜单,分别用于绘制多边形、矩形和椭圆:
1. 绘制多边形:
```python
import turtle
def draw_polygon():
sides = int(input("请输入多边形的边数:"))
length = int(input("请输入每条边的长度:"))
pen = turtle.Turtle()
for i in range(sides):
pen.forward(length)
pen.right(360/sides)
turtle.done()
# 调用函数
draw_polygon()
```
2. 绘制矩形:
```python
import turtle
def draw_rectangle():
width = int(input("请输入矩形的宽度:"))
height = int(input("请输入矩形的高度:"))
pen = turtle.Turtle()
for i in range(2):
pen.forward(width)
pen.right(90)
pen.forward(height)
pen.right(90)
turtle.done()
# 调用函数
draw_rectangle()
```
3. 绘制椭圆:
```python
import turtle
def draw_ellipse():
a = int(input("请输入椭圆的长半轴:"))
b = int(input("请输入椭圆的短半轴:"))
pen = turtle.Turtle()
pen.speed(10)
for i in range(2):
pen.circle(a, 90)
pen.circle(b, 90)
turtle.done()
# 调用函数
draw_ellipse()
```
阅读全文