如何在Python中获取输入的特定部分,以及多段inpu

2024-04-25 01:03:38 发布

您现在位置:Python中文网/ 问答频道 /正文

这是一个由两部分组成的问题。我正在用python3制作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,每次输入,并且在运行它时保存它,就像你去在线仿真器一样?你知道吗


Tags: inforinputbasicexample方式tirange
2条回答
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

如果您希望用户输入1乘1:

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
#Declare a list
a = []

#Set a range for loop where N<20.
for x in range (19): 

    #Display "Example"
    print("Example")

    #Append "Example" to your 'a' list.
    a.append("Example")

# printing the list using loop 
for x in range(len(a)): 
    print a[x]

相关问题 更多 >