Please what's wrong with this code | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 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"))

4th May 2022, 8:31 AM
FrankE
FrankE - avatar
8 ответов
+ 3
What is the aim of your code?
4th May 2022, 12:36 PM
⚡parky
⚡parky - avatar
+ 1
once try by doing this, word=word.replace("1","one") print(word)
5th May 2022, 5:27 AM
Ritwik Tat
Ritwik Tat - avatar
+ 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))
6th May 2022, 4:45 AM
Tegar Sabila
Tegar Sabila - avatar
+ 1
Thanks a lot you guys
8th May 2022, 10:58 AM
FrankE
FrankE - avatar
0
In supposed to turn any numeral ranging from 0 -10 in a string to words
4th May 2022, 12:42 PM
FrankE
FrankE - avatar
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..
4th May 2022, 12:48 PM
Jayakrishna 🇮🇳
0
oh god elif
5th May 2022, 3:55 AM
Valentine Bucket
Valentine Bucket - avatar
0
Put the zero statement on top and at the last use else for ten
5th May 2022, 4:29 PM
Muhammad Rehan
Muhammad Rehan - avatar