本文整理匯總了Python中machine.Machine.execute_program方法的典型用法代碼示例。如果您正苦於以下問題:Python Machine.execute_program方法的具體用法?Python Machine.execute_program怎麽用?Python Machine.execute_program使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類machine.Machine
的用法示例。
在下文中一共展示了Machine.execute_program方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: print
# 需要導入模塊: from machine import Machine [as 別名]
# 或者: from machine.Machine import execute_program [as 別名]
#!/usr/bin/env python3
import sys
from machine import read_instructions_from_file
from machine import Machine
usage_message = (
"./run.py part infile\n"
"e.g. ...\n"
"./run.py part-1 input.txt\n"
"./run.py part-2 input.txt\n"
"./run.py both input.txt\n"
)
if (len(sys.argv) != 3):
print(usage_message)
instructions = read_instructions_from_file(sys.argv[2])
if sys.argv[1] == "part-1" or sys.argv[1] == "both":
machine = Machine()
machine.execute_program(instructions)
print("PART 1 ANSWER -- Register A: %d --- Register B: %d"
% (machine.registers["a"], machine.registers["b"]))
if sys.argv[1] == "part-2" or sys.argv[1] == "both":
machine = Machine(1)
machine.execute_program(instructions)
print("PART 2 ANSWER -- Register A: %d --- Register B: %d"
% (machine.registers["a"], machine.registers["b"]))