python coding challenge
Watch this thread
Announcements
Page 1 of 1
Skip to page:
veish
Badges:
3
Rep:
?
You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#1
I received this challenge at schl and I'm not sure abt how to answer it
---------------------------------------------------------------------------------------------------------
Digit Words
A digit word is a word where, after possibly removing some letters, you are left with one of the single digits: ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT or NINE.
For example:
BOUNCE and ANNOUNCE are digit words, since they contain the digit ONE.
ENCODE is not a digit word, even though it contains an O, N and E, since they are not in order.
Write a program which reads in a single upper-case word (with at most fifteen letters) and determines if it is a digit word.
If the word is not a digit word you should output the word NO.
If the word is a digit word you should output the digit it contains, as a number.
We will not be testing any words which contain more than one digit.
---------------------------------------------------------------------------------------------------------
Digit Words
A digit word is a word where, after possibly removing some letters, you are left with one of the single digits: ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT or NINE.
For example:
BOUNCE and ANNOUNCE are digit words, since they contain the digit ONE.
ENCODE is not a digit word, even though it contains an O, N and E, since they are not in order.
Write a program which reads in a single upper-case word (with at most fifteen letters) and determines if it is a digit word.
If the word is not a digit word you should output the word NO.
If the word is a digit word you should output the digit it contains, as a number.
We will not be testing any words which contain more than one digit.
0
reply
Composure
Badges:
9
Rep:
?
You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#2
veish
Badges:
3
Rep:
?
You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#3
(Original post by Composure)
Have you at least attempted to code it?
Have you at least attempted to code it?
0
reply
veish
Badges:
3
Rep:
?
You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#4
(Original post by veish)
yh but i couldnt get the answer during class
yh but i couldnt get the answer during class
0
reply
mqb2766
Badges:
19
Rep:
?
You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#5
Report
#5
(Original post by veish)
i just wanna see how others would attempt this problem so that i can learn from it
i just wanna see how others would attempt this problem so that i can learn from it
0
reply
Composure
Badges:
9
Rep:
?
You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#6
Report
#6
(Original post by veish)
yh but i couldnt get the answer during class
yh but i couldnt get the answer during class
Last edited by Composure; 8 months ago
0
reply
veish
Badges:
3
Rep:
?
You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#7
(Original post by mqb2766)
Why not post what you've tried?
Why not post what you've tried?
def dw():
message = input("what is your word: ")
for char in message:
if char == "O" and char== "N" and char== "E" :
print ("one")
dw()
i was trying to make the first part work and then once i got that i could copy paste for the rest of the code just changing the letters
0
reply
mqb2766
Badges:
19
Rep:
?
You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#8
Report
#8
(Original post by veish)
im really new to python so my code is very simple and it doesnt work at all but here it is
def dw():
message = input("what is your word: ")
for char in message:
if char == "O" and char== "N" and char== "E" :
print ("one")
dw()
i was trying to make the first part work and then once i got that i could copy paste for the rest of the code just changing the letters
im really new to python so my code is very simple and it doesnt work at all but here it is
def dw():
message = input("what is your word: ")
for char in message:
if char == "O" and char== "N" and char== "E" :
print ("one")
dw()
i was trying to make the first part work and then once i got that i could copy paste for the rest of the code just changing the letters
ONE
You could print out
char
each time round the loop to understand what your test means, or use the debugger.
0
reply
Composure
Badges:
9
Rep:
?
You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#9
Report
#9
(Original post by veish)
im really new to python so my code is very simple and it doesnt work at all but here it is
def dw():
message = input("what is your word: ")
for char in message:
if char == "O" and char== "N" and char== "E" :
print ("one")
dw()
i was trying to make the first part work and then once i got that i could copy paste for the rest of the code just changing the letters
im really new to python so my code is very simple and it doesnt work at all but here it is
def dw():
message = input("what is your word: ")
for char in message:
if char == "O" and char== "N" and char== "E" :
print ("one")
dw()
i was trying to make the first part work and then once i got that i could copy paste for the rest of the code just changing the letters
The solution requires knowledge of mutability, indexing, arguments, parameters, exception raising, containers, iterables, iterators, standard library modules, boolean logic, conditions, and returns. If your teacher hasn't covered these then there's not much you can do ¯\_(ツ)_/¯
Last edited by Composure; 8 months ago
1
reply
veish
Badges:
3
Rep:
?
You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#10
(Original post by Composure)
If this is the level you're at then I don't think there's a real point in attempting the question as it's way above what a beginner would be capable of.
The solution requires knowledge of mutability, indexing, arguments, parameters, exception raising, containers, iterables, iterators, standard library modules, boolean logic, conditions, and returns. If your teacher hasn't covered these then there's not much you can do ¯\_(ツ)_/¯
If this is the level you're at then I don't think there's a real point in attempting the question as it's way above what a beginner would be capable of.
The solution requires knowledge of mutability, indexing, arguments, parameters, exception raising, containers, iterables, iterators, standard library modules, boolean logic, conditions, and returns. If your teacher hasn't covered these then there's not much you can do ¯\_(ツ)_/¯
0
reply
mqb2766
Badges:
19
Rep:
?
You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#11
Report
#11
(Original post by veish)
oh ok thanks anyways
oh ok thanks anyways
0
reply
Composure
Badges:
9
Rep:
?
You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#12
Report
#12
(Original post by veish)
oh ok thanks anyways
oh ok thanks anyways
To give some feedback on your code from earlier:
(Original post by veish)
Line 1. def dw():
Line 1. def dw():
(Original post by veish)
Line 2. message = input("what is your word: ")
Line 2. message = input("what is your word: ")
(Original post by veish)
Line 3. for char in message:
Line 3. for char in message:
(Original post by veish)
Line 4. if char == "O" and char== "N" and char== "E" :
Line 4. if char == "O" and char== "N" and char== "E" :
(Original post by veish)
Line 5. print("one")
Line 5. print("one")
Last edited by Composure; 8 months ago
0
reply
PossiblyNotGod
Badges:
20
Rep:
?
You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#13
Report
#13
so the code would be something like:
Code:
words_list = [[O,N,E],[T,W,O],[T,H,R,E,E]...] inputted_word = input() def get_answer(): word_is_digit_word = False i = 0 for digit_word in words_list: order_iter = 0 for letter in inputted_word: if letter == digit_word[order_iter]: if order_iter < len(digit_word): order_iter += 1 else: word_is_digit_word = True return word_is_digit_word, i i += 1 return word_is_digit_word, i word_is_digit_word, i = get_answer() print('was it a digit word?: ', word_is_digit_word) if word_is_digit_word: print('which word was it?: , words_list[i])
Last edited by PossiblyNotGod; 8 months ago
0
reply
CompSciJP
Badges:
14
Rep:
?
You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#14
Report
#14
(Original post by veish)
I received this challenge at schl and I'm not sure abt how to answer it
---------------------------------------------------------------------------------------------------------
Digit Words
A digit word is a word where, after possibly removing some letters, you are left with one of the single digits: ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT or NINE.
For example:
BOUNCE and ANNOUNCE are digit words, since they contain the digit ONE.
ENCODE is not a digit word, even though it contains an O, N and E, since they are not in order.
Write a program which reads in a single upper-case word (with at most fifteen letters) and determines if it is a digit word.
If the word is not a digit word you should output the word NO.
If the word is a digit word you should output the digit it contains, as a number.
We will not be testing any words which contain more than one digit.
I received this challenge at schl and I'm not sure abt how to answer it
---------------------------------------------------------------------------------------------------------
Digit Words
A digit word is a word where, after possibly removing some letters, you are left with one of the single digits: ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT or NINE.
For example:
BOUNCE and ANNOUNCE are digit words, since they contain the digit ONE.
ENCODE is not a digit word, even though it contains an O, N and E, since they are not in order.
Write a program which reads in a single upper-case word (with at most fifteen letters) and determines if it is a digit word.
If the word is not a digit word you should output the word NO.
If the word is a digit word you should output the digit it contains, as a number.
We will not be testing any words which contain more than one digit.

Break the question down, design the code and then implement your design. "Best by test"

0
reply
X
Page 1 of 1
Skip to page:
Quick Reply
Back
to top
to top