Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 正在获取Word 2 Num的输入_Python - Fatal编程技术网

Python 正在获取Word 2 Num的输入

Python 正在获取Word 2 Num的输入,python,Python,我试着把代码写在需要用户输入的地方,而不是把它放在打印行中。有人能帮我吗 def toNum(words, num={}): if not num: teens = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen","sixteen", "s

我试着把代码写在需要用户输入的地方,而不是把它放在打印行中。有人能帮我吗

def toNum(words, num={}):
    if not num:
        teens = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen","sixteen", "seventeen", "eighteen", "nineteen",]
        tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
        hund = ["hundred", "thousand"]


        num["and"] = (1, 0)
        for idx, word in enumerate(teens): num[word] = (1, idx)
        for idx, word in enumerate(tens): num[word] = (1, idx * 10)
        for idx, word in enumerate(hund): num[word] = (10 ** (idx * 3 or 2), 0)

        input = result = 0
        for word in words.split():
                if word not in num:
                        raise Exception(word)

                hund, increment = num[word]
                input = input * hund + increment
                if hund > 100:
                        result += input
                        input = 0

        return result + input

print toNum("seventy three hundred")
#here I want it to ask for user input instead of my having to write it in the code. Not sure how to apply it to the rest of the code. 
print toNum(raw_input("Enter a number: "))