What is the error in my code? | SoloLearn: Learn to code for FREE!

+5

What is the error in my code?

https://www.sololearn.com/coach/55?ref=app

8/3/2020 5:06:50 PM

Jayendra Todawat

14 Answers

New Answer

+11

The task can be done in a rather simple way: (1) take the input string and reverse it (2) create an empty list for final result (3) use a for loop to iterate over the input string (4) in for loop check if character from input string isalpha() or if it is a space (5) If yes: append this character to the final list (6) use final list and ''.join() elements and print the result

+13

How will we know the error without debugging and how will we debug when we don't have the code. Show us your attempt.

+11

ord(33) to ord(65) does not cover all the characters that must be skip. Why don't you reverse the process instead of finding characters which shouldn't be in output, why not instead find the ones that are needed to be shown as output(the alphabets) for example: finding only the alphabets instead REVERSING YOUR LOGIC: message=str(input()) mes=list(message) mes.reverse() mes1=[] for i in mes: if (ord(i) >= 65 and ord(i) <= 90) or (ord(i) >= 97 and ord(i) <= 122) or ord(i)==32: mes1.append(i) print(''.join(mes1)) ________________________________________ here's more improvement, why use list when we can achieve the same result using string message=str(input()) mes=list(message) mes1="" for i in mes: if (ord(i) >= 65 and ord(i) <= 90) or (ord(i) >= 97 and ord(i) <= 122) or ord(i)==32: mes1+=i print(mes1[::-1]) # "socat" is reversed here to our output - "tacos"

+9

Jayndra Todawat , post your code linked to Playground so somebody can help you.

+7

x=str(input()) a=[] b="".join(filter(lambda x:x.isalpha(),x)) for i in x: if i in b or i==" ": a.append(i) d="".join(a) print(d[::-1]) this is what lothar said

+6

As TheWh¡teCat 🇧🇬 and Rohit mentioned, can you give us your code. I mean, otherwise how should we know what's the error? Thanks 😉.

+6

Sorry guys Rohit TheWh¡teCat 🇧🇬 Blue_Ocean Here is my code n=0 message=str(input()) mes=list(message) mes.reverse() mes1=[] for i in mes: k=mes[n] j=ord(k) if j in range(33,65): mes.remove(k) else: mes1.append(k) n+=1 mes3=' '.join(mes1) print(mes3)

+6

Rohit Thanx

+6

Ayush Rastogi Yes bro its worked Thnx

+6

Lothar Yes I have done it in the manner u say.. Thnx for help

+5

Jayndra Todawat You forgot about space add this if k==' ': mes1.append(k) And modify this mes3=''. join(mes1) (no space)

+5

[email protected]😏😏 Thanks but It didn't work. I think I must change my logic

+5

s=input() x=s[::-1] st="" for i in range(len(x)): if x[i] in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ": st+=x[i] print(st) Try this.

-1

Lol... 😂😂😂😂