程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python] learning notes week11-0 list

編輯:Python

【PYTHON】 Input list , Find the sum of list elements # list

Title Description

Enter the list in one line , Output the sum of list elements .

Input

Enter a list... In one line .

Output

Output the sum of the list elements in one line .

The sample input

[3,8,-5]

Sample output

6

a=eval(input())
print("{}".format(sum(a)))

【PYTHON】 Sub list in the output list # list

Title Description

The user enters a list and 2 It's an integer ,2 An integer as a subscript , Then the output list is mediated in 2 A sublist of elements between subscripts

Input

The first line of string The second line is two integers , Comma interval

Output

Intercepted sublist

The sample input

HappyNationalDay 5,12

Sample output

['N', 'a', 't', 'i', 'o', 'n', 'a', 'l']

a=list(input())
b,c=map(eval,input().split(","))
print(a[b:c+1])

【PYTHON】 Calculate the sum of odd numbers in the list # list

Title Description

Calculate the sum of odd numbers in the list .

Input

Input integer list

Output

Output the odd sum in the list

The sample input

[1,2,3,4,5,6,7,9]

Sample output

25

a=eval(input())
sum=0
for i in a:
if i%2==1:
sum=sum+i
print(sum)

【PYTHON】 Ascending sort # list

Title Description

Enter several positive integers , Output after ascending sort .

Input

Enter several numbers in one line , Space off .

Output

Output list sorted in ascending order

The sample input

4 5 67 3 99 2 7

Sample output

[2, 3, 4, 5, 7, 67, 99]

a=list(map(eval,input().split(" ")))
a.sort()
print(a)

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved