int一下s
或者eval
你把代码复制出来呗
# 已知字符串pi = 3.141592653589793 ,请统计各数字出现的次数,并按升序打印输出。
pi = 3.141592653589793 num_dict = ____1____ for s in pi: # 判断 s 是否为数字0-9 if ____2____ if s in num_dict: ____3____ else: num_dict[s] = 1 # 对字典按键排序 num_list = ____4____ print( 数字\t\t出现次数 ) for num in num_list: print( {}\t\t{}次 .format(____5____))
你的源码是怎样的?
pi = 3.141592653589793 num_dict = {} for s in pi: if s in 0 1 2 3 4 5 6 7 8 9 : if s in num_dict: num_dict[s] += 1 else: num_dict[s] = 1 num_list = list(num_dict) print( 数字\t\t出现次数 ) for num in num_list: print( {}\t\t{}次 .format(num,num_dict[num]))
6,多谢