利用turtle库用7段码的方式打印 bad cafe这几个字母
时间: 2023-06-04 11:06:14 浏览: 110
好的,下面是利用turtle库用7段码的方式打印 bad cafe 这几个字母的代码:
```python
import turtle
# 定义 7 段码
codes = {
'0': [(0, 1), (0, 4), (1, 0), (1, 5), (2, 0), (2, 5), (3, 0), (3, 5), (4, 1), (4, 4)],
'1': [(0, 2), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5)],
'2': [(0, 1), (0, 2), (0, 3), (1, 0), (2, 3), (3, 2), (4, 1), (4, 2), (4, 3), (4, 4)],
'3': [(0, 1), (0, 2), (0, 3), (1, 0), (2, 3), (3, 2), (3, 3), (4, 1), (4, 4)],
'4': [(0, 0), (1, 0), (1, 3), (2, 3), (3, 1), (3, 2), (3, 3), (3, 4), (4, 3)],
'5': [(0, 0), (0, 1), (0, 2), (0, 3), (1, 0), (2, 3), (3, 2), (3, 3), (4, 1), (4, 4)],
'6': [(0, 1), (0, 2), (0, 3), (1, 0), (2, 3), (3, 0), (3, 2), (3, 3), (4, 1), (4, 4)],
'7': [(0, 0), (0, 1), (1, 2), (2, 1), (2, 2), (2, 3), (3, 0), (4, 0)],
'8': [(0, 1), (0, 2), (0, 3), (1, 0), (1, 5), (2, 3), (3, 0), (3, 3), (4, 1), (4, 4)],
'9': [(0, 1), (0, 2), (0, 3), (1, 0), (1, 5), (2, 3), (3, 2), (3, 3), (4, 1), (4, 4)],
'a': [(0, 1), (0, 2), (0, 3), (1, 0), (2, 1), (2, 3), (3, 1), (3, 3), (4, 2), (4, 3)],
'b': [(0, 0), (0, 1), (0, 2), (0, 3), (1, 0), (1, 4), (2, 0), (2, 4), (3, 0), (3, 4), (4, 1), (4, 2), (4, 3)],
'c': [(0, 1), (0, 2), (0, 3), (1, 0), (4, 1), (4, 2), (4, 3)],
'd': [(0, 0), (0, 1), (0, 2), (0, 3), (1, 0), (1, 4), (2, 0), (2, 4), (3, 0), (3, 4), (4, 1), (4, 2), (4, 3)],
'e': [(0, 0), (0, 1), (0, 2), (0, 3), (1, 0), (2, 0), (2, 2), (2, 3), (3, 0), (4, 0), (4, 1), (4, 2), (4, 3)],
'f': [(0, 0), (0, 1), (0, 2), (0, 3), (1, 0), (2, 0), (2, 2), (2, 3), (3, 0), (4, 0)]
}
# 定义打印函数
def draw_letter(letter):
turtle.penup()
turtle.goto(30 * letter_idx, 0)
turtle.pendown()
for x, y in codes[letter]:
turtle.goto(x * 10, (y * 10) - 35)
text = 'bad cafe'
# 打印每个字母
for letter_idx, letter in enumerate(text):
if letter in codes:
draw_letter(letter)
turtle.done()
```
运行代码后,屏幕上将会显示出用 7 段码的方式打印出的 bad cafe 字母。
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)