本文整理汇总了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"]))