+ 2
Spy Life Code
Hi! I’m having trouble with my code for the Spy Life challenge. Can someone tell me the issue in this code? import re input = input() output = re.sub(r"[^\w\s]", "", input) list = list(output) for i in list: if i == '1' or i == '2' or i == '3' or i == '4' or i == '5' or i == '6' or i == '7' or i == '8' or i == '9' or i == '0': list.remove(i) else: continue list.reverse() final = "".join(list) print(final)
6 Antworten
+ 13
David Ashton Thank you so much!
With your advice, I came up with a new way to solve the problem that worked!
input = input()
list = []
for i in input:
if i.isalpha():
list.append(i)
elif i == " ":
list.append(i)
else:
continue
list.reverse()
final = "".join(list)
print(final)
+ 12
OR!ON I agree with not simply providing the answer in lesson quiz comments and with not disclosing pro code coach questions. The code I wrote is set at private and does not disclose the code coach problem, which is not a pro question. Eden is pursuing a different approach, which I offered some suggestions for. I have not yet seen (although I have explicitly asked for) a definitive answer on this situation. I shared my particular creation, which approaches the problem from a different angle, in the spirit of helping others to learn to code, not helping them gobble up XP. If it is permissible to give a series of hints which make solving a code coach question easy for anyone reading the thread, I don't see a real difference. I'm open to being persuaded otherwise. 🙂
+ 4
I don't see why it's failing the second test, but I don't use regex because I'm pretty weak in that area.
Your 'if' statement could be a bit shorter, e g.
if i in "124567890":
or better -
if i.isdigit():
Here's my code
https://code.sololearn.com/cY9RGgh74WLj
+ 2
David Ashton Directly providing solution?
+ 1
The second testcase is not being passed
My output:youaregreat
Expected output:you are great
This is my code
string=input()
list1=[]
i=0
length=len(string)
while(i<length):
for letter in range(97,123):
if(string[i]==chr(letter)):
temp=list1.append(chr(letter))
else:
letter+=1
i+=1
str=""
str1=str.join(list1[::-1])
print(str1)
0
x = input()
y = x[::-1]
txt = ""
for i in y:
if i.isalpha() or i == " ":
txt += i
print(txt)