+ 1
Please what's wrong with this code
word = input().lower() if "1" in word: print(word.replace("1", "one")) elif "0" in word: print(word.replace("0", "zero")) elif "2" in word: print(word.replace("2", "two")) elif "3" in word: print(word.replace("3", "three")) elif "4" in word: print(word.replace("4", "four")) elif "5" in word: print(word.replace("5", "five")) elif "6" in word: print(word.replace("6", "six")) elif "7" in word: print(word.replace("7", "seven")) elif "8" in word: print(word.replace("8", "eight")) elif "9" in word: print(word.replace("9", "nine")) elif "10" in word: print(word.replace("10", "ten"))
8 Respostas
+ 3
What is the aim of your code?
+ 1
once try by doing this,
word=word.replace("1","one")
print(word)
+ 1
Solved Problem
This is correct program
num = ['zero','one','two','three','four','five','six','seven','eight','nine']
def number2(n):
# If all the digits are encountered return blank string
if(n==0):
return ""
else:
# compute spelling for the last digit
small_ans = num[n%10]
# keep computing for the previous digits and add the spelling for the last digit
ans = number2(int(n/10)) + small_ans + " "
# Return the final answer
return ans
print("( Number To Word Converted )")
n = int(input("Enter Number: "))
print("Converted to word: ",end="")
print(number2(n))
+ 1
Thanks a lot you guys
0
In supposed to turn any numeral ranging from 0 -10 in a string to words
0
First write case 10 before 1 and 0 otherwise its output onezero for 10
edit:
FrankE and only print one time at last....
you need all if there.. not elif, by this approach....
in fact, no need of if-else block checks.. you can directly write
word.replace (...).word.replace(..)... in sequence also..
0
oh god elif
0
Put the zero statement on top and at the last use else for ten