如何编写一个Python程序来读取输入并将其转换为带有海龟图形的预定义14段字符?
我已经编写了定义十四个段的海龟图形函数,以及将这些段组装成字符的函数,例如
def MethodA (width) :
top_stroke(width)
middle_stroke(width)
left_stroke
right_stroke(width)
我已经准备好所有定义,但是如何让python读取输入并将输入的字符转换为我之前定义的十四段形式?
理想情况下,如果我输入“Pizza”,程序应该以十四段形式输出字符“PIZZA”。
任何建议都受到欢迎和赞赏。谢谢,
I have written the turtle graphics functions that define the fourteen segments, and the functions that assemble these segments to form characters, e.g.
def MethodA (width) :
top_stroke(width)
middle_stroke(width)
left_stroke
right_stroke(width)
I have all the definitions ready, but how do I let python to read an input and convert the characters of the input into the fourteen segments forms, which I defined previously?
Idealy, if I enter "Pizza", the program should produce the output of the characters 'PIZZA' in the fourteen-segments form.
Any suggestions are welcomed and appreciated. Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以定义一个带有函数引用的字典,如下所示:
然后,对于字符串
s
:此代码使用
Characters[c]
在字典中查找函数引用,然后(width)
导致函数被调用(使用width
参数,正如函数所期望的那样)。You could define a dictionary with function references like this:
Then, for a string
s
:This code works using
Characters[c]
to look up the function reference in the dictionary, then the(width)
causes the function to be called (with awidth
parameter, as the function expects).