python實(shí)現(xiàn)機(jī)器人卡牌
介紹
這個例子主要利用turtle庫實(shí)現(xiàn)根據(jù)輸入動態(tài)展示不同機(jī)器人的圖像和屬性信息。
代碼部分非原創(chuàng)只是做了些許修改和整理使得更易閱讀。
圖片和文件資源請訪問git倉庫獲?。?a rel="external nofollow" target="_blank" >鏈接地址
涉及以下知識點(diǎn):
1.文件讀取
2.字典
3.turtle庫的使用
4.控制語句
實(shí)現(xiàn)的效果
代碼
#!/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') # 將文件中機(jī)器人信息裝載到字典中 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) # 將當(dāng)前位置上的形狀復(fù)制到畫布上 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!")
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Python實(shí)現(xiàn)企業(yè)微信機(jī)器人每天定時發(fā)消息實(shí)例
- Python調(diào)用釘釘自定義機(jī)器人的實(shí)現(xiàn)
- Python使用微信接入圖靈機(jī)器人過程解析
- 基于python的itchat庫實(shí)現(xiàn)微信聊天機(jī)器人(推薦)
- Python實(shí)現(xiàn)微信機(jī)器人的方法
- Python3從零開始搭建一個語音對話機(jī)器人的實(shí)現(xiàn)
- 基于Python的微信機(jī)器人開發(fā) 微信登錄和獲取好友列表實(shí)現(xiàn)解析
- Python實(shí)現(xiàn)微信翻譯機(jī)器人的方法
- Python qqbot 實(shí)現(xiàn)qq機(jī)器人的示例代碼
- python實(shí)現(xiàn)微信自動回復(fù)機(jī)器人功能
- 如何用Python做一個微信機(jī)器人自動拉群
- Python QQBot庫的QQ聊天機(jī)器人
- 使用python接入微信聊天機(jī)器人
- itchat-python搭建微信機(jī)器人(附示例)
- python實(shí)現(xiàn)微信機(jī)器人: 登錄微信、消息接收、自動回復(fù)功能
- 手把手教你使用Python創(chuàng)建微信機(jī)器人
- python控制nao機(jī)器人身體動作實(shí)例詳解
- Python開發(fā)企業(yè)微信機(jī)器人每天定時發(fā)消息實(shí)例
相關(guān)文章
15行Python代碼實(shí)現(xiàn)免費(fèi)發(fā)送手機(jī)短信推送消息功能
這篇文章主要介紹了通過15行Python代碼實(shí)現(xiàn)免費(fèi)發(fā)送手機(jī)短信推送消息功能,通過實(shí)例代碼截圖的形式給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2020-02-02解決python問題 Traceback (most recent call&n
這篇文章主要介紹了解決python問題 Traceback (most recent call last),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-12-12Python操作word實(shí)現(xiàn)添加文字或圖片水印
這篇文章主要為大家詳細(xì)介紹了如何使用Spire.Doc for Python在程序中的輕松添加文字和圖像水印到Word文檔,感興趣的小伙伴可以跟隨小編一起了解一下2023-10-10Python使用smtplib?實(shí)現(xiàn)單發(fā)和群發(fā)郵件驗證碼
這篇文章主要介紹了Python使用smtplib?實(shí)現(xiàn)單發(fā)和群發(fā)郵件驗證碼,文章通過使用?smtplib?模塊在?Python?中發(fā)送電子郵件,需要的小伙伴可以參考一下2022-05-05Python實(shí)現(xiàn)圖片轉(zhuǎn)字符畫的代碼實(shí)例
今天小編就為大家分享一篇關(guān)于Python實(shí)現(xiàn)圖片轉(zhuǎn)字符畫的代碼實(shí)例,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-02-02python 安裝virtualenv和virtualenvwrapper的方法
下面小編就為大家?guī)硪黄猵ython 安裝virtualenv和virtualenvwrapper的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-01-01