这是一个由两部分组成的问题。我正在努力用 Python 3 制作一个 Ti-basic 模拟器/翻译器。我想要的是这样的东西:
0->N
while N<20
disp "example"
input "example",a
N+1->N
end
Python 中的 Ti-basic 等价物:
for n in range(0,20):
print("Example")
a=input("Example")
以更简单的方式,我希望它在第一行显示 Disp "example"
,将其翻译为 Python:
print((text in quotations after disp, "Example" in this case))
两个问题:
一:
如何分隔输入的各个部分,以便当具有 disp
的任何行都知道放置 print()
并将带引号的区域放入打印的括号?
两个:
如何获得多行输入,这样我就不必为每个输入逐行输入 Ti-basic,并在运行时保存它,就像您使用在线模拟器一样?
最佳答案
a = [] #Create a list to store your values
for n in range (0, 20):
print('Example')
a.append('Example') #Add 'Example' string to list
print (a) #See all items in the list
如果您希望用户逐一键入输入:
a = [] #Create a list to store your values
for n in range (0, 20):
sample = input('Please key in your input: ') #Be aware that inputs are by default str type in Python3
a.append(sample) #Add sample string to list
print (a) #See all items in the list
关于python - 如何在Python中获取输入的特定部分以及多段落输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53808235/