l1993520
发表于 2017-8-31 05:51:23
kankandashen
疯子的快乐
发表于 2017-9-2 19:54:03
看大神
骚强么么哒
发表于 2017-9-2 20:00:16
围观
克里斯蒂亚诺
发表于 2017-9-4 12:47:38
def average(string):
nums = str.split(string,' ')
correspond = ['one','two','three','four','five',
'six','seven','eight','nine']
n_sum = 0
for each in nums:
if each in correspond:
n_sum = n_sum+correspond.index(each)+1
else:
return 'n /a'
a_num = n_sum/len(nums)
return correspond
if __name__=='__main__':
e_num = input('input your english numbers:')
result = average(e_num)
print(result)
lihuayuan
发表于 2017-9-11 19:32:02
不知道
谱写未来
发表于 2017-9-12 08:46:41
看看答案
总有理
发表于 2017-9-16 11:34:10
n/a 不大会做,其他的代码用for循环打了一下
def average_string(str1):
num = {'zero':0,'one':1,'two':2,'three':3,'four':4,'five':5,'six':6,'seven':7,'eight':8,'nine':9}
list1=[]
for i in num:
if i in str1:
list1.append(num.get(i))
average = 0
for i in list1:
average+=i
average = average/len(list1)
return average
py交易老李
发表于 2017-9-24 19:49:20
{:5_91:}
胡先生
发表于 2017-9-26 09:59:39
看看大神
shigure_takimi
发表于 2017-12-4 17:13:21
def average_string(string):
english = ['zero','one','two','three','four','five','six','seven','eight','nine']
newList =
numberList = []
for word in newList:
if word in english:
numberList.append(english.index(word))
else:
print('n / a')
return None
print(english)
average_string('one three two')
average_string('five five five')
average_string('ku fthj two')
lebroncm
发表于 2017-12-8 19:05:43
def average_string(i):
sum=0
a=['zero','two','one','three','four','five','six','seven','eight','nine']
b=
d=dict(zip(a,b))
e=i.split()
for each in e:
if each in a:
sum=sum+d
else:
return 'n/a'
return sum/len(e)
凌九霄
发表于 2018-3-31 23:40:14
本帖最后由 凌九霄 于 2018-3-31 23:44 编辑
def average_string(s):
stringN = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
num = 0
i = 0
lst = s.split(" ")
for x in lst:
if x in stringN:
num += stringN.index(x)
if num > 9 :
return 'n/a'
break
i += 1
else:
return 'n/a'
return stringN
DavidCowboy
发表于 2018-8-17 16:56:33
def average_string(x,y,z):
list1 = ['zero','one','two','three','four','five','six','seven','eight','nine']
while x in list1 and y in list1 and z in list1:
sum1 = list1.index(x) + list1.index(y) + list1.index(z)
return sum1
else:
print('n/a')
子沙
发表于 2018-8-18 13:17:00
def average_string(num):
num=str(num)
list_num=['zero','one','two','three','four','five','six','seven','eight','nine']
m=0
n=0
for i in list_num:
p=num.count(i)
m+=p*list_num.index(i)
n+=p
num=num.replace(i,'')
k=0
if num.count(' ')==len(num):
print(list_num)
else:
print('n/a')
average_string('one two six')
average_string('dad six')
小木子c
发表于 2018-8-18 16:51:05
观摩
兀颜光
发表于 2018-8-21 13:43:42
啊啊啊所
jiaozhu80
发表于 2018-8-27 20:07:05
本帖最后由 jiaozhu80 于 2018-8-27 20:10 编辑
def average_atring(string):
m={"one":1,"two":2,"three":3,"four":4,"five":5,"six":6,"seven":7,"eight":8,
"nine":9,"zero":0}
list1=string.split()
sum=0
for a in list1:
if a in m.keys():
sum+=m.get(a)
else:
return "n/a"
average=int(sum/len(list1))
for key,value in m.items():
if average == value:
average=key
return average
gx112345
发表于 2018-8-28 12:08:06
不相同的地方,很多很多
咕咕鸡鸽鸽
发表于 2019-2-26 15:44:19
dict1 = {"zero":0,
"one":1,
"two":2,
"three":3,
"four":4,
"five":5,
"six":6,
"seven":7,
"eight":8,
"nine":9}
def fun78(str1):
list1 = str1.split(" ")
list2 = []
for each in list1:
try:
temp = dict1
except:
return "n / a"
list2.append(temp)
avg = sum(list2) // (len(list2))
for key,value in dict1.items():
if avg == value:
return key
print(fun78("one nine two"))
print(fun78("one ten two"))
哇嘎哩恭
发表于 2019-2-26 16:24:23
1