当前位置:网站首页>R7-1 sum of numeric elements of a list or tuple
R7-1 sum of numeric elements of a list or tuple
2022-06-11 22:21:00 【*Advanced road*】
Find the sum of numbers in the list , The nesting level in the list is unlimited 2 layer
Input format :
Enter a list or tuple on one line
Output format :
Output the sum of numbers in one line
sample input :
Here's a set of inputs . for example :
[11,2,[3,7],(68,-1),"123",9]
sample output :
Here is the corresponding output . for example :
99Code :
def sum1(x):
s=0
for i in x:
if type(i)==list or type(i)==tuple:
s+=sum1(i)
elif type(i)==int or type(i)==float:
s+=i
return s
x=eval(input())
t=0
for i in x:
if type(i)==list or type(i)==tuple:
t+=sum1(i)
elif type(i)==int or type(i)==float:
t+=i
print(t)
边栏推荐
- The college entrance examination is over, and life has just begun. Suggestions from a 10-year veteran in the workplace
- Implementation of stack stack
- Superscalar processor design yaoyongbin Chapter 2 cache -- Excerpt from subsection 2.3
- 被忽略的技巧:位运算
- Basic operation and question type summary of binary tree
- Maze problem in C language
- 启牛商学院送华泰账户安不安全?真的吗
- Explain asynchronous tasks in detail: the task of function calculation triggers de duplication
- R language book learning 03 "in simple terms R language data analysis" - Chapter 7 linear regression model
- Precision twist jitter
猜你喜欢

详解异步任务:函数计算的任务触发去重

Players must read starfish NFT advanced introduction
![[Yu Yue education] Yancheng Normal University Advanced Algebra reference](/img/3f/cd7f6f420fb1d453acca9aa73665ba.jpg)
[Yu Yue education] Yancheng Normal University Advanced Algebra reference

什么是死锁?(把死锁给大家讲明白,知道是什么,为什么用,怎么用)

Tkinter study notes (IV)

If I take the college entrance examination again, I will study mathematics well!

Win10弹出USB时出现该设备正在使用的解决方法

How to adjust the font blur of win10

A simple example of linear regression in machine learning

Zhanrui IOT chip 8910dm is certified by Deutsche Telekom
随机推荐
Regular execution of shell scripts in crontab
[Yu Yue education] Yancheng Normal University Advanced Algebra reference
Superscalar processor design yaoyongbin Chapter 2 cache -- Excerpt from subsection 2.2
[uniapp native plug-in] shangmi cashbox plug-in
链表基本操作与题型总结
Stack栈的实现
Implementation of sequencelist sequence table
判断链表是否为回文结构
二叉树的基本操作与题型总结
leetcode 257. Binary tree paths all paths to a binary tree (simple)
Uncover the secret of the popular app. Why is it so black
C language implements eight sorts (3)
inner join执行计划变了
Leetcode stack topic summary
Unity3D getLaunchIntentForPackage 获取包返回null问题
Go encoding package
69. square root of X
大学三年应该这样过
238. product of arrays other than itself
Addition without addition, subtraction, multiplication, Division