admin 管理员组

文章数量: 1086019


2023年12月22日发(作者:sscanf根据逗号分割)

一些好玩的代码

以下是一些好玩的Python代码:。

1.猜数字游戏。

```python。

import random。

num = t(1,100)。

while True:。

guess = int(input("猜一个1到100之间的数字: "))if guess == num:。

print("恭喜你,猜对了!")。

break。

elif guess < num:。

print("你猜的数字太小了,请重新猜!")。

elif guess > num:。

print("你猜的数字太大了,请重新猜!")。

```。

2.打印彩虹颜色。

```python。

import turtle。

colors = ["red", "orange", "yellow", "green", "blue",

"purple"]。

(0)。

()。

(-350,0)。

n()。

for i in range(600):。

or(colors[i % len(colors)])。

d(i)。

(121)。

```。

3.画一个心形。

```python。

import turtle。

(0)。

("red")。

_fill()。

(140)。

d(180)。

(-90, 200)。

ding(60)。

(-90, 200)。

d(180)。

_fill()。

()。

```。

4.绘制一个迷宫。

```python。

import turtle。

import random。

(0)。

#绘制边界。

()。

(-300, 300)。

n()。

(-300, -300)。

(300, -300)。

(300, 300)。

(-300, 300)。

#随机生成迷宫。

for i in range(-280, 281, 20):。

for j in range(-280, 281, 20):。

if () > 0.7:。

()。

(i, j)。


本文标签: 逗号 数字 迷宫 绘制 好玩