一个关于程序中的程序小问题
各位大佬大家好!我最近想设计一个程序,作用是它让你输入一个程序,可以无限换行,直到输入q为止,接着它会运行你刚才输入的每一行,并输出结果(不支持运行在程序里输入的程序),请问,能做到吗?示例:请输入一个程序:
print("Hello,world!")
q
好的!你的程序运行结果:
Hello,world!
还要再输入程序吗?(y/n)
n
程序结束,下次再来哦!
2022-05-22 11:03
程序代码:CodeStr=""
while True:
while True:
str=input("请输入一行代码:")
if str!="q":
CodeStr=CodeStr + str + '\n'
else:
break
print("好的!你的程序运行结果:")
exec(CodeStr)
if input("还要再输入程序吗?(y/n)")=="n":break
CodeStr=""
2022-05-22 14:04
2022-05-23 15:34