+ 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
31 Respuestas
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
+ 6
https://code.sololearn.com/cj1ys91nj0k3/?ref=app
+ 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]))
+ 4
Just put "ten" before "zero" and remove line 12
Less Line + Simple Logic = Better Code
+ 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)
+ 4
If you can write a solution that solves it faster than this - let me know.
https://code.sololearn.com/c07MxmkRmsN4/?ref=app
+ 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;
}
+ 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))
+ 2
The code is so long but it is very easy to understand.
+ 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.
+ 1
Thank you for your feed back
+ 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=" ")
+ 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
+ 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)
+ 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.
+ 1
chalupa bazooka, thanks for finding the error)
0
https://code.sololearn.com/c1mTl6QxcF9K/?ref=app
This code takes any large number as it is and prints it out!
0
What's the error in this code it can't pass case3