+ 1
Anyone help me to find what is wrong in this code?some test cases only passed
8 Answers
+ 6
Arun Venkatesh.N ,
the task description says:
... remove any characters that are not a letter or a space ... this means that we only have to care for *letters* and for *spaces*.
although your code is a bit cumbersome, it can be corrected:
> add this at the end of your *if* conditional:
if(..., i=='Z' or i== ' '):
^^^^^^^^
in general i would recommend you to keep things sinple. we can use a for loop for iterating though the input string and check if the current character is a letter by using isalpha() or a space by using isspace()
> this can be used like:
...
if char.isalpha() or char.isspace():
...
these are the steps to go:
> create a variable to store the output string
> take the input, reverse it and store it in a variable like *msg*
> iterate through the input like: for char in msg:
> check the content of variable char as described above
> if char is a letter or a space, concatenate it to the final string
> output the final string
+ 2
Jenny Buenaflor Pls do not:
1. Post question as comment in another question. Create your own post instead.
2. Ask people to write code. Post questions to guide you to write it instead.
+ 1
With my code...if it is a single word the test cases passed but for sentence..it doesn't work..for sentence also my output print without space
Eg:o&âčl()l_âče-&-h':-i'&+(h
Original output:hi hello
For me,
hihello it prints....
+ 1
import re
inp = input()
print(''.join(re.findall(r'[a-zA-Z]|\s', inp[::-1]))) # the \s stands for the space!
+ 1
Mahmmoud Khalid ,
Now also it didn't work.. without space the sentence get printed
+ 1
Thank you Lothar bro âșïž
all test cases passed... thankyou
0
Do you have a task that this is with?
- 1
Write a program that will accept your username and password if they do not match display "login failed" otherwise "welcome"
Username: student1
Password: xxx