代码拉取完成,页面将自动刷新
#!/bin/python3
from turtle import *
from random import choice
screen = Screen()
screen.setup(400, 400)
screen.bgcolor('white')
penup()
hideturtle()
robots = {}
file = open('resource/cards.txt', 'r')
# 将文件中机器人信息装载到字典中
for line in file.read().splitlines():
name, battery, intelligence, usefulness, speed, image, colour = line.split(', ')
robots[name] = [battery, intelligence, usefulness, speed, image, colour]
screen.register_shape('img/' + image)
file.close()
print('Robots: ', ', '.join(robots.keys()), ' (or random)')
while True:
robot = input("Choose a robot: ")
if robot == "random":
robot = choice(list(robots.keys()))
print(robot)
if robot in robots:
stats = robots[robot]
style = ('Courier', 14, 'bold')
clear()
color(stats[5])
goto(0, 100)
shape('img/' + stats[4])
setheading(90)
# 将当前位置上的形状复制到画布上
stamp()
setheading(-90)
forward(70)
write('Name: ' + robot, font=style, align='center')
forward(25)
write('Battery: ' + stats[0], font=style, align='center')
forward(25)
write('Intelligence: ' + stats[1], font=style, align='center')
forward(25)
write('Usefulness: ' + stats[2], font=style, align='center')
forward(25)
write('Speed: ' + stats[3], font=style, align='center')
else:
print("Robot doesn't exist!")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。