当前位置:网站首页>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 device is in use when win10 ejects USB
- One question of the day - delete duplicates of the ordered array
- [Yu Yue education] basic engineering English of Zhejiang industrial and Commercial University (wuyiping) reference materials
- 3.3 测试模块的命名规则
- MATLAB点云处理(二十五):点云生成 DEM(pc2dem)
- 超標量處理器設計 姚永斌 第2章 Cache --2.4 小節摘錄
- Analysis of the implementation principle of an open source markdown to rich text editor
- Players must read starfish NFT advanced introduction
- leetcode 257. Binary tree paths all paths to a binary tree (simple)
- Maze problem in C language
猜你喜欢

The device is in use when win10 ejects USB

电脑强制关机 oracle登录不上
![[niuke.com] dp31 [template] complete Backpack](/img/81/5f35a58c48f05a5b4b6bdc106f5da0.jpg)
[niuke.com] dp31 [template] complete Backpack

Collection of articles and literatures related to R language (continuously updated)

Implementation stack and queue

Internet of things development practice 18 scenario linkage: how does an intelligent light perceive light? (I) (learning notes)

超标量处理器设计 姚永斌 第2章 Cache --2.2 小节摘录

6.项目上线

Conception du Processeur superscalaire Yao yongbin chapitre 2 cache - - sous - section 2.4 extrait

Tkinter学习笔记(二)
随机推荐
C language implements eight sorts (1)
Go OS module
[Yu Yue education] basic engineering English of Zhejiang industrial and Commercial University (wuyiping) reference materials
論文閱讀《Dense Visual SLAM for RGB-D Cameras》
MySQL事务简介
Tkinter study notes (II)
Top - K problem
Custom implementation offsetof
Tkinter学习笔记(三)
Superscalar processor design yaoyongbin Chapter 2 cache -- Excerpt from subsection 2.3
Explain asynchronous tasks in detail: the task of function calculation triggers de duplication
3.2 测试类的命名规则
被忽略的技巧:位运算
玩家必读|Starfish NFT进阶攻略
LeetCode栈题目总结
Study notes of mattlotlib and Tkinter (I)
Three methods of quick sorting
69. square root of X
A simple example of linear regression in machine learning
Are you still using localstorage directly? It's time to raise the bar