How can I print ten with this code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How can I print ten with this code

This code just prints one0 but how can I do it to print ten not one0 This is the code: def no_numerals(phrase): translation = "" number_letters = { "1": "one", "2": "two", "3": "three", "4": "four", "5": "five", "6": "six", "7": "seven", "8": "eight", "9": "nine", "10": "ten", } for letter in phrase: if letter in number_letters: translation = translation + number_letters[letter] else: translation = translation + letter else: print(translation) no_numerals(str(input()))

27th Dec 2019, 4:33 PM
Progress Osemudiamen Emuan
Progress Osemudiamen Emuan - avatar
17 Answers
+ 10
Like this.. def no_numerals(phrase): number_letters = { "1": "one", "2": "two", "3": "three", "4": "four", "5": "five", "6": "six", "7": "seven", "8": "eight", "9": "nine", "10": "ten", } print (number_letters.get (phrase,phrase)) no_numerals(str(input()))
27th Dec 2019, 5:12 PM
𝘕𝘉
𝘕𝘉 - avatar
+ 8
As we are dealing with one input only for loop can be avoided
27th Dec 2019, 5:16 PM
𝘕𝘉
𝘕𝘉 - avatar
+ 7
You can use after number_letters dictionary print (number_letters.get (phrase,phrase))
27th Dec 2019, 5:09 PM
𝘕𝘉
𝘕𝘉 - avatar
+ 6
Updated for multiple inputs def no_numerals(phrase): number_letters = { "1": "one", "2": "two", "3": "three", "4": "four", "5": "five", "6": "six", "7": "seven", "8": "eight", "9": "nine", "10": "ten", } for l in phrase: print (number_letters.get (l,l)) no_numerals(str(input()).split (" ")) ''' for eg: 10 6 #gives ten six'"'
27th Dec 2019, 5:37 PM
𝘕𝘉
𝘕𝘉 - avatar
+ 6
https://code.sololearn.com/c7vKNzr1dkTo/?ref=app Enter inputs by pressing enter in between
27th Dec 2019, 7:06 PM
𝘕𝘉
𝘕𝘉 - avatar
+ 6
https://code.sololearn.com/c55cG9aw6Cc5/?ref=app give multiple inputs by giving one space each in between them.
28th Dec 2019, 4:52 PM
𝘕𝘉
𝘕𝘉 - avatar
+ 6
You want to get outputs in same line?
28th Dec 2019, 5:03 PM
𝘕𝘉
𝘕𝘉 - avatar
+ 6
https://code.sololearn.com/c7vKNzr1dkTo/?ref=app You can get outputs in same line
28th Dec 2019, 5:08 PM
𝘕𝘉
𝘕𝘉 - avatar
+ 6
You are most welcome
28th Dec 2019, 5:09 PM
𝘕𝘉
𝘕𝘉 - avatar
29th Dec 2019, 8:32 AM
𝘕𝘉
𝘕𝘉 - avatar
+ 2
Thank a lot
28th Dec 2019, 5:08 PM
Progress Osemudiamen Emuan
Progress Osemudiamen Emuan - avatar
+ 1
Nirmalya Bakshi It works thanks just that I can'mix it with other letters
27th Dec 2019, 5:13 PM
Progress Osemudiamen Emuan
Progress Osemudiamen Emuan - avatar
+ 1
Nirmalya Bakshi Doesn't work
27th Dec 2019, 5:39 PM
Progress Osemudiamen Emuan
Progress Osemudiamen Emuan - avatar
+ 1
Nirmalya Bakshi how would it work in the same line
28th Dec 2019, 10:12 AM
Progress Osemudiamen Emuan
Progress Osemudiamen Emuan - avatar
+ 1
Nirmalya Bakshi there is not one space between them
28th Dec 2019, 4:57 PM
Progress Osemudiamen Emuan
Progress Osemudiamen Emuan - avatar
+ 1
Yes
28th Dec 2019, 5:03 PM
Progress Osemudiamen Emuan
Progress Osemudiamen Emuan - avatar
+ 1
Nirmalya Bakshi there is a problem you can't do as the function you can print numbers alone but you can't do it mixed with other strings or different texts apart from the ones in the dictionary See I want this that will make me to be able to do this ##hello 10 outputs with the function ##Hello ten ##hi bro 3 ##hi bro three thanks
28th Dec 2019, 8:50 PM
Progress Osemudiamen Emuan
Progress Osemudiamen Emuan - avatar