如下,是使用python定义一个函数,请问有什么问题?

This function receives as input a string which may contain letters, digits or special symbols.The function should return the sum of adding the digits in the string. 

An example addDigitsInString('a12bcd3') should return 6

蛊毒传说
浏览 95回答 2
2回答

翻过高山走不出你

使用关键词 def 声明这是一个函数1def 函数名 (参数):2 语句块参数可以没有,也可以有多个,用逗号隔开,第一行称为函数头,结尾一定要加冒号,代表开始进入函数体的执行。语句块也就是函数体,是关于这个函数要实现的功能的语句,语句要有返回值即return语句,如果没有return语句,就代表return none.

慕工程0101907

#! /usr/bin/env python# coding: UTF-8# python3.3  def func(test_str):    '''deal with the str'''    standard_list = []    for i in range(10):        standard_list.append(str(i))    sum = 0    for str_ in test_str:        if str_ in standard_list:            sum = sum + int(str_)    return sum if __name__ == '__main__':    test_str = 'da1asda5ad3ad2'    value = func(test_str)    print(value)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python