No numerals | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

No numerals

On this topic, it’s passed the tests, but I don’t think it’s strong, is there someone that did this better? https://code.sololearn.com/cWTQ0unetI8H/?ref=app

17th Jan 2020, 9:14 AM
Douglas
31 Answers
0
It doesn't. If you pass "Hi 22", your program returns "Hi twotwo", when it should leave the number as a number when it's over 10. With the standard solution maybe you will pass the cases uses of the No Numerals tests, but any number greater than 10 will be treated like 22: twotwo. Here is a much stronger solution. https://code.sololearn.com/cWf709EgZCz1/?ref=app
17th Jan 2020, 9:36 AM
Felipe Santa-Cruz
Felipe Santa-Cruz - avatar
+ 6
https://code.sololearn.com/cj1ys91nj0k3/?ref=app
17th Jan 2020, 4:39 PM
Aliman
Aliman - avatar
+ 5
sent = (input()) dict = {"1": "one", "2": "two", "3": "three", "4": "four", "5": "five", "6": "six", "7": "seven", "8": "eight", "9":"nine", "10": "ten"} sentlst = sent.split(" ") print(" ".join([dict.get(n, n) for n in sentlst]))
3rd Mar 2021, 3:35 AM
tom
tom - avatar
+ 4
Just put "ten" before "zero" and remove line 12 Less Line + Simple Logic = Better Code
17th Jan 2020, 10:41 AM
Yash Chaudhari
Yash Chaudhari - avatar
+ 4
inp = input() words = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'] for each in inp.split(' '): if each.isdigit(): inp = inp.replace(each, words[int(each)]) print(inp)
23rd Jan 2020, 12:28 AM
Onuoha_ifeanyi
Onuoha_ifeanyi - avatar
+ 4
If you can write a solution that solves it faster than this - let me know. https://code.sololearn.com/c07MxmkRmsN4/?ref=app
5th Jul 2021, 6:25 PM
Rokas Karabevičius
Rokas Karabevičius - avatar
+ 3
C++ program of no numerals #include<iostream> #include<string> using namespace std; int main(){ string s; getline(cin,s); for(int i=0;i<s.length();i++){ char c=s[i]; if(s[i]=='1'&&s[i+1]=='0'){ s.replace(i,2 ,"ten"); } else if(c=='0'){ s.replace(i,1,"zero"); } else if(c=='1'){ s.replace(i,1,"one"); } else if(c=='2'){ s.replace(i,1,"two"); } else if(c=='3'){ s.replace(i,1,"three"); } else if(c=='4'){ s.replace(i,1,"four"); } else if(c=='5'){ s.replace(i,1,"five"); } else if(c=='6'){ s.replace(i,1,"six"); } else if(c=='7'){ s.replace(i,1,"seven"); } else if(c=='8'){ s.replace(i,1,"eight"); } else if(c=='9'){ s.replace(i,1,"nine"); } } cout<<s; return 0; }
18th Aug 2020, 3:04 AM
namrata singh
namrata singh - avatar
+ 2
def check_num(letter): return letter in '012345678910' def number_in_text(letter): ret_letter = '' if letter == '0': ret_letter = 'zero' elif letter == '1': ret_letter = 'one' elif letter == '2': ret_letter = 'two' elif letter == '3': ret_letter = 'three' elif letter == '4': ret_letter = 'four' elif letter == '5': ret_letter = 'five' elif letter == '6': ret_letter = 'six' elif letter == '7': ret_letter = 'seven' elif letter == '8': ret_letter = 'eight' elif letter == '9': ret_letter = 'nine' elif letter == '10': ret_letter = 'ten' else: pass return ret_letter sentence = input() list1 = list(map(str, sentence.split())) list2 = [] for letter in list1: if check_num(letter): list2.append(number_in_text(letter)) else: list2.append(letter) print(' '.join(list2))
26th Jun 2020, 10:31 AM
Pranit Bhoir
Pranit Bhoir - avatar
+ 2
The code is so long but it is very easy to understand.
26th Jun 2020, 10:32 AM
Pranit Bhoir
Pranit Bhoir - avatar
+ 2
*Task: Take a phrase and replace any instances of an integer from 0-10 and replace it with the English word that corresponds to that integer.* It doesn't says that the phrase can't content integers greater than 10. And the user is asking for a stronger solution.
18th Aug 2020, 4:49 PM
Felipe Santa-Cruz
Felipe Santa-Cruz - avatar
+ 1
Thank you for your feed back
18th Jan 2020, 6:29 AM
Douglas
+ 1
n=list(map(str,input().split(" "))) m=("zero","one","two","three","four","five","six","seven","eight","nine","ten") N=("0","1","2","3","4","5","6","7","8","9","10") for i in n: if i in N: q=n.index(i) p=N.index(i) n[q]=m[p] for j in n: print(j,end=" ")
17th Aug 2020, 1:14 PM
venkata santhosh
+ 1
namrata singh When a two digit or more digit no. is entered it outputs each digits word. Ex: Input: Room no. 347 Output: Room no. threefourseven Input: 22 apples Output: twotwo apples
18th Aug 2020, 4:01 AM
SREEHARI A H
SREEHARI A H - avatar
+ 1
word = input() cout = word.replace("0","zero").replace("1","one").replace("2","two").replace("3","three").replace("4","four").replace("5","five").replace("6","six").replace("7","seven").replace("8","eight").replace("9","nine").replace("onezero","ten") print(cout)
16th Dec 2021, 4:31 AM
Samnith Vath
Samnith Vath - avatar
+ 1
@Onuoha_ifeanyi I have an issue with your option: whenever an input contains numerals greater than 10 (i.e. greater than the biggest number on the list) Python returns an IndexError. For example, if the input is "15 cupcakes", the program just won't work since there's no item with index 15 on the list. Because of that your replace-function solution won't cope with it. However, I like your idea in general, it looks clean and smart. Perhaps, there's some way to set a range for the isdigit function? Sorry, I'm new to Python and coding in general, so my suggestion might seem weird.
24th Dec 2021, 4:38 PM
chalupa bazooka
chalupa bazooka - avatar
+ 1
chalupa bazooka, thanks for finding the error)
13th Feb 2022, 7:52 AM
Bohdan Bashenko
Bohdan Bashenko - avatar
0
https://code.sololearn.com/c1mTl6QxcF9K/?ref=app This code takes any large number as it is and prints it out!
17th Aug 2020, 6:41 PM
SREEHARI A H
SREEHARI A H - avatar
0
What's the error in this code it can't pass case3
2nd May 2021, 9:39 AM
Mr.Dark
Mr.Dark - avatar