I have written the turtle graphics functions that define the fourteen segments, and the functions that assemble these segments to form characters, eg
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,
You could define a dictionary with function references like this:
Characters = {
'A': MethodA,
'B': MethodB,
# ...
}
Then, for a string s
:
s = "Pizza"
for c in s:
c = c.upper() # to fold lowercase into upper case
if c in Characters:
Characters[c](width)
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 a width
parameter, as the function expects).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.