+ 1

Anyone help me to find what is wrong in this code?some test cases only passed

https://code.sololearn.com/cs9dF13pmn0B/?ref=app

10th Oct 2022, 10:56 AM
Venkatesh
Venkatesh - avatar
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
10th Oct 2022, 4:56 PM
Lothar
Lothar - avatar
+ 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.
11th Oct 2022, 4:15 AM
Emerson Prado
Emerson Prado - avatar
+ 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....
10th Oct 2022, 11:47 AM
Venkatesh
Venkatesh - avatar
+ 1
import re inp = input() print(''.join(re.findall(r'[a-zA-Z]|\s', inp[::-1]))) # the \s stands for the space!
10th Oct 2022, 12:05 PM
Mahmmoud Khalid
Mahmmoud Khalid - avatar
+ 1
Mahmmoud Khalid , Now also it didn't work.. without space the sentence get printed
10th Oct 2022, 12:14 PM
Venkatesh
Venkatesh - avatar
+ 1
Thank you Lothar bro â˜ș all test cases passed... thankyou
10th Oct 2022, 7:20 PM
Venkatesh
Venkatesh - avatar
0
Do you have a task that this is with?
10th Oct 2022, 11:26 AM
Ausgrindtube
Ausgrindtube - avatar
- 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
11th Oct 2022, 12:29 AM
Jenny Buenaflor
Jenny Buenaflor - avatar