기본 정보 처리 기술자 시험 Pythhon의 샘플 문제는 외부 프로그램 라이브러리를 사용하지 않고 실현되었다
2623 단어 기본 정보 처리 기술자 시험샘플 문제Python
https://www.jitec.ipa.go.jp/1_00topic/topic_20191028.html
matplotlib이라는 외부 프로그램 라이브러리를 사용합니다.
Python 3을 설치하기만 하면 이 샘플을 실행할 수 없습니다.
따라서 외부 프로그램 라이브러리를 사용하지 않고 터틀 모듈만 사용합니다.
제가 소개하겠습니다.
"""
命令列はファイルから読み込む
ファイル名はコマンド引数で指定する
"""
import sys
import turtle
import re
def parse(str):
return [(x[0], int(x[1:])) for x in str.split(';')]
def draw_init():
turtle.shape('turtle')
turtle.home()
turtle.clear()
def draw(str):
opelist = parse(str)
stack = []
openo = 0
while openo < len(opelist):
code, num = opelist[openo]
if code == 'U':
turtle.penup()
elif code == 'D':
turtle.pendown()
elif code == 'F':
turtle.forward(num)
elif code == 'B':
turtle.backward(num)
elif code == 'T':
turtle.left(num)
elif code == 'H':
turtle.home()
elif code == 'X':
turtle.setx(num)
elif code == 'Y':
turtle.sety(num)
elif code == 'R':
stack.append({'openo': openo, 'rest': num})
elif code == 'E':
if stack[-1]['rest'] > 1:
openo = stack[-1]['openo']
stack[-1]['rest'] -= 1
elif stack[-1]['rest'] <= 1:
stack.pop() #stackの末尾の要素を削除する
openo += 1
#コマンド引数からファイル名を取り出す
filename = sys.argv[1]
#ファイルを開き、操作の文字列を読み込む
try:
file = open(filename)
opestr = file.read()
opestr = re.sub('#.*\n', '', opestr) #コメントを行末まではぎ取る
opestr = re.sub(' \t\n', '', opestr) #空白行をはぎ取る
opestr = re.sub(r"([A-Z]{1})", r";\1", opestr) #区切りのセミコロンを挿入する
opestr = opestr.lstrip(";") #先頭の余分なセミコロンを削除する
#描画する
draw_init()
draw(opestr)
#例外の処理を行う
except Exception as e:
print(e)
#ファイルを閉じる
finally:
file.close()
다음은 조작 파일의 예를 소개한다.#点線の星を描く
R5
R20
D0
F5
U0
F5
E0
T216
E0
<실행 결과>Reference
이 문제에 관하여(기본 정보 처리 기술자 시험 Pythhon의 샘플 문제는 외부 프로그램 라이브러리를 사용하지 않고 실현되었다), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/aocyan/items/ff1f4fb2b50d3fbd34de텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)