Write a program that creates a function fff()
to show a table with #
randomly distributed in those 9 blocks. The following shows an execution of the program.
>>> fff()
# #
##
#
Since you will use the module random, please add import random at the beginning of your program so that you can use random.random() > 0.8 . The statement random.random() randomly generates a number in (0,1). Note that any number in (0,1) can be a threshold instead of 0.8 .
from turtle import Turtle, Screen
import random
import colorgram
import turtle as t
#设置颜色类型为RGB格式,默认为字符串
t.colormode(255)
tim = Turtle()
#设置一个随机的方向选择
options=[0,90,180,270]
#生成随机的RGB元组
def randomcolor():
r= random.randint(0,255)
g= random.randint(0,255)
b = random.randint(0, 255)
return (r,g,b)
tim.speed('fastest')
#随机选择一个方向,选择一个颜色,线条加粗
def randomwalk():
tim.setheading(random.choice(options))
tim.color(randomcolor())
tim.speed('fast')
tim.pensize(10)
tim.forward(20)
for i in range(100):
randomwalk()
screen = Screen()
screen.exitonclick()
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632
非常感谢您使用有问必答服务,为了后续更快速的帮您解决问题,现诚邀您参与有问必答体验反馈。您的建议将会运用到我们的产品优化中,希望能得到您的支持与协助!
速戳参与调研>>>https://t.csdnimg.cn/Kf0y