int对象不是python中的下标错误

时间:2019-06-23 04:30:16

标签: python

我的代码是否可以简化清单:- 我收到

的错误
  

int对象不可下标

const sentence = context.activity.text.replace('!guggy ', '');

async function postRequest(x) {
    return await axios.post('http://exampleurl.here.com/helpapi', {
            "sentence" : x,
            "lang": "ru"
            },{
                headers: {
                    "Content-Type":"application/json",
                    "apiKey":"example-key-2020202"
                }
            });
}

try {
    const response = await postRequest(sentence);
} catch (error) {
    console.log(error);
}

console.log(response.data.animated[0].gif.original.url);
apiResponse = response.data.animated[0].gif.original.url;
await context.sendActivity(apiResponse);

3 个答案:

答案 0 :(得分:1)

使用以下代码:

l = list(map(int, input("Enter a nested list : ").split()))
total = 0
for i in l:
    total += i

print(total)

输出

Enter a nested list : 1 2 3
6

答案 1 :(得分:0)

首先使用str()将输入作为字符串,然后将其存储在l中,然后使用list()将其转换为列表。

您还可以通过list(input(“ text”))

直接将输入转换为列表。

答案 2 :(得分:0)

l =list( map( int, input("Enter a nested list : ").split() ))
print(sum(l))

1)。在这里,您必须按空格后输入值,例如25 then press space then next number and so on

2)。它将为您提供列表的总和,与列表的展平相同。