用脚本写一个满天星光的程序
时间: 2023-11-06 18:04:35 浏览: 47
以下是Python代码实现一个满天星光的程序:
```python
import random
# 定义星星的字符集
star_chars = ["★", "☆", "✩", "✦", "✪", "✫", "✬", "✭", "✮", "✯", "✰", "✱", "✲", "✳", "✴", "✵", "✶", "✷", "✸", "✹", "✺", "✻", "✼", "✽", "✾", "✿", "❀", "❁", "❂", "❃", "❄", "❅", "❆", "❇", "❈", "❉", "❊", "❋", "❌", "❍", "❎", "❏", "❐", "❑", "❒", "❓", "❔", "❕", "❖", "❗", "❘", "❙", "❚", "❛", "❜", "❝", "❞", "❟", "❠", "❡", "❢", "❣", "❤", "❥", "❦", "❧"]
# 随机生成星星的数量
num_stars = random.randint(50, 100)
# 随机生成星星的坐标
coords = []
for i in range(num_stars):
x = random.randint(0, 70)
y = random.randint(0, 20)
coords.append((x, y))
# 输出星星
for y in range(21):
for x in range(71):
if (x, y) in coords:
print(random.choice(star_chars), end="")
else:
print(" ", end="")
print()
```
运行该程序,会在终端输出一个满天星光的效果。每次运行程序都会生成不同数量和位置的星星,以及随机选择不同的星星字符。