请你写一个五颜六色的表白python程序
时间: 2023-04-08 18:03:42 浏览: 60
我可以回答这个问题。以下是一个五颜六色的表白 Python 程序:
```
import random
colors = ['\033[91m', '\033[92m', '\033[93m', '\033[94m', '\033[95m', '\033[96m']
message = "我喜欢你,愿意和你在一起。"
for char in message:
color = random.choice(colors)
print(color + char, end='')
print('\033[0m')
```
这个程序会随机选择颜色,然后逐个字符地输出表白信息。希望你喜欢!
相关问题
帮我使用python当中的turtle 画一个五颜六色的小房子
好的,以下是使用 Python 的 turtle 库画一个五颜六色的小房子的代码:
```python
import turtle
# 画红色的房子
turtle.color("red")
turtle.begin_fill()
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.end_fill()
# 画黄色的屋顶
turtle.color("yellow")
turtle.begin_fill()
turtle.left(45)
turtle.forward(70.7)
turtle.right(90)
turtle.forward(70.7)
turtle.end_fill()
# 画绿色的草地
turtle.penup()
turtle.goto(-150, -100)
turtle.pendown()
turtle.color("green")
turtle.begin_fill()
turtle.forward(400)
turtle.right(90)
turtle.forward(200)
turtle.right(90)
turtle.forward(400)
turtle.right(90)
turtle.forward(200)
turtle.end_fill()
# 画蓝色的天空
turtle.penup()
turtle.goto(-150, 100)
turtle.pendown()
turtle.color("blue")
turtle.begin_fill()
turtle.forward(400)
turtle.right(90)
turtle.forward(200)
turtle.right(90)
turtle.forward(400)
turtle.right(90)
turtle.forward(200)
turtle.end_fill()
# 画紫色的门
turtle.penup()
turtle.goto(25, -100)
turtle.pendown()
turtle.color("purple")
turtle.begin_fill()
turtle.forward(50)
turtle.left(90)
turtle.forward(80)
turtle.left(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(80)
turtle.end_fill()
# 画橙色的窗户
turtle.penup()
turtle.goto(75, 0)
turtle.pendown()
turtle.color("orange")
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
turtle.done()
```
希望这个代码能够帮到你!
用python代码画一幅五颜六色的星空
```python
import turtle
import random
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor('black')
# 定义星星函数
def draw_star(x, y, color, size):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.color(color)
turtle.begin_fill()
for i in range(5):
turtle.forward(size)
turtle.right(144)
turtle.end_fill()
# 随机生成星星
for i in range(100):
x = random.randint(-400, 400)
y = random.randint(-300, 300)
color = random.choice(['white', 'yellow', 'red', 'blue', 'green', 'purple'])
size = random.randint(5, 25)
draw_star(x, y, color, size)
# 隐藏画笔
turtle.hideturtle()
# 显示画布
turtle.done()
```
--相关问题--:
1. 如何在Python中使用turtle库画图?
2.