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()))
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()))
+ 8
As we are dealing with one input only for loop can be avoided
+ 7
You can use after number_letters dictionary
print (number_letters.get (phrase,phrase))
+ 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'"'
+ 6
https://code.sololearn.com/c7vKNzr1dkTo/?ref=app
Enter inputs by pressing enter in between
+ 6
https://code.sololearn.com/c55cG9aw6Cc5/?ref=app
give multiple inputs by giving one space each in between them.
+ 6
You want to get outputs in same line?
+ 6
https://code.sololearn.com/c7vKNzr1dkTo/?ref=app
You can get outputs in same line
+ 6
You are most welcome
+ 2
Thank a lot
+ 1
Nirmalya Bakshi It works thanks just that I can'mix it with other letters
+ 1
Nirmalya Bakshi Doesn't work
+ 1
Nirmalya Bakshi how would it work in the same line
+ 1
Nirmalya Bakshi there is not one space between them
+ 1
Yes
+ 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