私はこの割り当てを持っています:
smallnr(x)
数値を受け取り、 がその間の整数である場合、数値の名前を返す関数を作成しx
ます。それ以外の場合は、単純に文字列として返します。x
0
6
x
私は次のことをしました:
def smallnr(x):
if x>6:
return str(x)
else:
lst=['zero','one','two','three','four','five','six']
return (lst[x])
それはうまくいきますが、今はこれをしなければなりません:
smallnr
パート a の関数を使用してconvertsmall(s)
、入力としてテキストを受け取り、名前に変換された小さな数字 (0 から 6 までの整数) を含むテキストs
を返す 関数を作成します。s
例えば、convertsmall('私には 5 人の兄弟と 2 人の姉妹、合計 7 人の兄弟がいます.') '私には 5 人の兄弟と 2 人の姉妹、合計 7 人の兄弟がいます.'
split()
どうにかして使用する必要があることはわかっていますisnumeric()
が、すべてをまとめて文字列内の数字だけを変更する方法がわかりません。
何かアドバイス?