【发布时间】:2020-09-14 07:33:00
【问题描述】:
function = input('Enter function')
a = input('do you want to enter another function')
b = [function]
if a.lower() == 'yes':
while True:
function1 = input('Next Function')
b += function1
if function1 == 'quit':
break
print(b)
如果我在 function1 中输入,则在此代码中:y = 9x + 1;它会将值放入数组中,但格式为:'y', ' ', '9x', ' ', '+', ' ', '1'。
如何将输入保存为y = 9x + 1'?
此外,当我写退出时,它会打印数组,但最终值为q','u','i','t'。
如何消除这些值?
【问题讨论】:
-
b.append(function1) 而不是 b+=
-
将
b += function1更改为b += [function1] -
谢谢,它有效,我设法从数组中删除了“退出”
-
你没有正确定义
b,所以才会有错误的答案
标签: python string list augmented-assignment