# Отчёт по теме 1. Знакомство с интерпретатором и интерактивной оболочкой IDLE Таболин Иван Андреевич А-01-23 #1. Создал свою папку на диске, а в ней создал папки TEMAn #2. Запустил на выполнение программу-интерпретатор, выбрав ее ярлык «Python 3.13». #3. 3.Изучил содержание открывающегося диалогового окна интерпретатора. Вывел "hello". ```py >>> print('Hello') Hello ``` #4. Запросил от пользователя имя и ввёл с клавиатуры. ```py >>> h=input('Your name=') Your name=Ivan ``` #5. Завершил работу интерпретатора. ```py >>> exit() ``` #6. Запустил интерактивную графическую оболочку IDLE среды Python. #7. Изучил устройство главного командного окна среды. #8. Настроил рабочий каталог среды ```py import os os.chdir('C:\MPEI\POAS\Tabolin\Tema1\python-labs\TEMA1') ``` #9. Изучил предложения главного меню и настроил интерфейс оболочки IDLE. #10. Создал файл программы и сохранил под именем Pr0.py. ```py --------Pr0.py-------- Программа по Теме 1 Таболин Иван Андреевич print('Hello') h=input('Your name=') import os os.chdir('C:\MPEI\POAS\Tabolin\Tema1\python-labs\TEMA1') ---------------------- ``` Запустил программу на выполнение разными способами. ```py import Pr0 Hello Your name=Ivan ``` #11. Запустил на выполнение Prb1.py ```py import prb1 Как Вас зовут? Ivan Привет, Ivan ``` #12. Содержание файла Pr0.cpython-34.pyc: ```py у ;Dµh° г  уP • \ " S 5 \" S5 rSSKr\R " S5 g)ЪHelloz Your name=й NzC:\MPEI\POAS\Tabolin\Tema1\)ЪprintЪinputЪhЪosЪchdir© у Ъ!C:\MPEI\POAS\Tabolin\Tema1\Pr0.pyЪr  s& рб Ђg„Щ€ УЂЫ Ш ‡‚Р +Х ,r ``` В папке __pycache__ содержится скомпилированный двоичный код, который нужен для оптимизации #13. Создал файл протокола темы. #14. Изучил раздел "Help" ```py help(print) Help on built-in function print in module builtins: print(*args, sep=' ', end='\n', file=None, flush=False) Prints the values to a stream, or to sys.stdout by default. sep string inserted between values, default a space. end string appended after the last value, default a newline. file a file-like object (stream); defaults to the current sys.stdout. flush whether to forcibly flush the stream. help(print),help(input) Help on built-in function print in module builtins: print(*args, sep=' ', end='\n', file=None, flush=False) Prints the values to a stream, or to sys.stdout by default. sep string inserted between values, default a space. end string appended after the last value, default a newline. file a file-like object (stream); defaults to the current sys.stdout. flush whether to forcibly flush the stream. Help on built-in function input in module builtins: input(prompt='', /) Read a string from standard input. The trailing newline is stripped. The prompt string, if given, is printed to standard output without a trailing newline before reading input. If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError. On *nix systems, readline is used if available. (None, None) ``` #15. Открыл файл prb1.py в текстовом редакторе среды. С помощью предложения "Window" переключался между окнами. Запустил программу prb1.py на выполнение с помощью предложения "Run". ```py ============================ RESTART: C:\MPEI\POAS\Tabolin\Tema1\prb1.py =========================== Как Вас зовут? Ivan Привет, Ivan ``` Открыл файл Pr0.py в текстовом редакторе среды и переключал окна. Закрыл два окна текстового редактора с помощью предложения "Close window". Запустил на выполнение программу tdemo_chaos.py и открыл сам код в текстовом редакторе. ```py import tdemo_chaos ``` tdemo_chaos.py ```py # File: tdemo_chaos.py # Author: Gregor Lingl # Date: 2009-06-24 # A demonstration of chaos from turtle import * N = 80 def f(x): return 3.9*x*(1-x) def g(x): return 3.9*(x-x**2) def h(x): return 3.9*x-3.9*x*x def jumpto(x, y): penup(); goto(x,y) def line(x1, y1, x2, y2): jumpto(x1, y1) pendown() goto(x2, y2) def coosys(): line(-1, 0, N+1, 0) line(0, -0.1, 0, 1.1) def plot(fun, start, color): pencolor(color) x = start jumpto(0, x) pendown() dot(5) for i in range(N): x=fun(x) goto(i+1,x) dot(5) def main(): reset() setworldcoordinates(-1.0,-0.1, N+1, 1.1) speed(0) hideturtle() coosys() plot(f, 0.35, "blue") plot(g, 0.35, "green") plot(h, 0.35, "red") # Now zoom in: for s in range(100): setworldcoordinates(0.5*s,-0.1, N+1, 1.1) return "Done!" if __name__ == "__main__": main() mainloop() ``` с помощью предложения "Help" открыл графическую демонстрацию "Turtle demo", а затем в появившемся окне открыл "Часы" и запустил программу "Start". Программа clock ```py #!/usr/bin/env python3 """ turtle-example-suite: turtledemo/clock.py Enhanced clock-program, showing date and time ------------------------------------ Press STOP to exit the program! ------------------------------------ """ from turtle import * from datetime import datetime dtfont = "TkFixedFont", 14, "bold" current_day = None def jump(distanz, winkel=0): penup() right(winkel) forward(distanz) left(winkel) pendown() def hand(laenge, spitze): fd(laenge*1.15) rt(90) fd(spitze/2.0) lt(120) fd(spitze) lt(120) fd(spitze) lt(120) fd(spitze/2.0) def make_hand_shape(name, laenge, spitze): reset() jump(-laenge*0.15) begin_poly() hand(laenge, spitze) end_poly() hand_form = get_poly() register_shape(name, hand_form) def clockface(radius): reset() pensize(7) for i in range(60): jump(radius) if i % 5 == 0: fd(25) jump(-radius-25) else: dot(3) jump(-radius) rt(6) def display_date_time(): global current_day writer.clear() now = datetime.now() current_day = now.day writer.home() writer.forward(distance=65) writer.write(wochentag(now), align="center", font=dtfont) writer.back(distance=150) writer.write(datum(now), align="center", font=dtfont) writer.forward(distance=85) def setup(): global second_hand, minute_hand, hour_hand, writer mode("logo") make_hand_shape("second_hand", 125, 25) make_hand_shape("minute_hand", 115, 25) make_hand_shape("hour_hand", 90, 25) clockface(160) second_hand = Turtle() second_hand.shape("second_hand") second_hand.color("gray20", "gray80") minute_hand = Turtle() minute_hand.shape("minute_hand") minute_hand.color("blue1", "red1") hour_hand = Turtle() hour_hand.shape("hour_hand") hour_hand.color("blue3", "red3") for hand in second_hand, minute_hand, hour_hand: hand.resizemode("user") hand.shapesize(1, 1, 3) hand.speed(0) ht() writer = Turtle() writer.ht() writer.pu() writer.bk(85) display_date_time() def wochentag(t): wochentag = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] return wochentag[t.weekday()] def datum(z): monat = ["Jan.", "Feb.", "Mar.", "Apr.", "May", "June", "July", "Aug.", "Sep.", "Oct.", "Nov.", "Dec."] j = z.year m = monat[z.month - 1] t = z.day return "%s %d %d" % (m, t, j) def tick(): t = datetime.today() sekunde = t.second + t.microsecond*0.000001 minute = t.minute + sekunde/60.0 stunde = t.hour + minute/60.0 try: tracer(False) # Terminator can occur here second_hand.setheading(6*sekunde) # or here minute_hand.setheading(6*minute) hour_hand.setheading(30*stunde) if t.day != current_day: display_date_time() tracer(True) ontimer(tick, 100) except Terminator: pass # turtledemo user pressed STOP def main(): tracer(False) setup() tracer(True) tick() return "EVENTLOOP" if __name__ == "__main__": mode("logo") msg = main() print(msg) mainloop() ```