Compare commits

..

No commits in common. "b1e76ba618c9132d8c0d82a86f9b98a6ca0f0ad4" and "e6a2f6eac73f4b95c7c368476f3122ba97a7c97a" have entirely different histories.

3 changed files with 0 additions and 121 deletions

View File

@ -40,15 +40,3 @@ extensions = [
``` ```
4. add `modules` after `Contents:` in `index.rst` 4. add `modules` after `Contents:` in `index.rst`
5. run `make.bat` 5. run `make.bat`
## Interpreters (2nd homework)
- [assignment](https://sciprogcentre.github.io/green-courses/pages/advanced_python/2023/hw/02.html)
- [solution](./interpreters)
## Turtle Device (3rd homework)
- [assignment](https://sciprogcentre.github.io/green-courses/pages/advanced_python/2023/hw/03.html)
- [solution](./turtle)
## Turtle Async (3rd homework)
- [assignment](https://sciprogcentre.github.io/green-courses/pages/advanced_python/2023/hw/04.html)
- [solution](./turtle_async)

View File

@ -1,35 +0,0 @@
import cmd
import threading
from queue import Queue
from equipment.turtle_device import TurtleDevice
class TurtleDeviceThread(threading.Thread):
# TODO(Homework 4)
def __init__(self):
super().__init__()
self.device = TurtleDevice()
self.queue = Queue()
class NoBlockingTurtleShell(cmd.Cmd):
intro = 'Welcome to the turtle shell. Type help or ? to list commands.\n'
prompt = '(turtle) '
file = None
def __init__(self, turtle_thread: TurtleDeviceThread):
pass # TODO(Homework 4)
def do_execute(self, arg):
pass # TODO(Homework 4)
def do_exit(self, arg):
pass # TODO(Homework 4)
if __name__ == '__main__':
turtle_thread = TurtleDeviceThread()
# TODO(Homework 4: Correct start thread)
NoBlockingTurtleShell(turtle_thread).cmdloop()

View File

@ -1,74 +0,0 @@
import cmd, sys
from turtle import *
class TurtleShell(cmd.Cmd):
intro = 'Welcome to the turtle shell. Type help or ? to list commands.\n'
prompt = '(turtle) '
file = None
# ----- basic turtle commands -----
def do_forward(self, arg):
'Move the turtle forward by the specified distance: FORWARD 10'
forward(*parse(arg))
def do_right(self, arg):
'Turn turtle right by given number of degrees: RIGHT 20'
right(*parse(arg))
def do_left(self, arg):
'Turn turtle left by given number of degrees: LEFT 90'
left(*parse(arg))
def do_goto(self, arg):
'Move turtle to an absolute position with changing orientation. GOTO 100 200'
goto(*parse(arg))
def do_home(self, arg):
'Return turtle to the home position: HOME'
home()
def do_circle(self, arg):
'Draw circle with given radius an options extent and steps: CIRCLE 50'
circle(*parse(arg))
def do_position(self, arg):
'Print the current turtle position: POSITION'
print('Current position is %d %d\n' % position())
def do_heading(self, arg):
'Print the current turtle heading in degrees: HEADING'
print('Current heading is %d\n' % (heading(),))
def do_color(self, arg):
'Set the color: COLOR BLUE'
color(arg.lower())
def do_undo(self, arg):
'Undo (repeatedly) the last turtle action(s): UNDO'
def do_reset(self, arg):
'Clear the screen and return turtle to center: RESET'
reset()
def do_bye(self, arg):
'Stop recording, close the turtle window, and exit: BYE'
print('Thank you for using Turtle')
self.close()
bye()
return True
# ----- record and playback -----
def do_record(self, arg):
'Save future commands to filename: RECORD rose.cmd'
self.file = open(arg, 'w')
def do_playback(self, arg):
'Playback commands from a file: PLAYBACK rose.cmd'
self.close()
with open(arg) as f:
self.cmdqueue.extend(f.read().splitlines())
def precmd(self, line):
line = line.lower()
if self.file and 'playback' not in line:
print(line, file=self.file)
return line
def close(self):
if self.file:
self.file.close()
self.file = None
def parse(arg):
'Convert a series of zero or more numbers to an argument tuple'
return tuple(map(int, arg.split()))
if __name__ == '__main__':
TurtleShell().cmdloop()