0

What is wrong in this??? This is the code for conversion of upper to lower and vice versa without using inbuilt function

str=input() char=input() for i in range(len(str)): if (char>64) and (char<91): char=char+32 print(char) elif (char>96) and (char<123): char=char-32 print(char) if char==32: print(" ") print(str)

2nd Aug 2021, 2:59 PM
Disha Jain
7 Antworten
+ 6
Disha Jain , there are several issues in the code: ▪︎you are using variable 'char' for comparing against upper or lower, this is not correct ▪︎in the for loop you get the individual characters of the string in the variable 'i'. ▪︎use 'i' after converting it to the ascii value by using ord() for the comparison => so the code has to be reworked happy coding and good success!
2nd Aug 2021, 3:38 PM
Lothar
Lothar - avatar
2nd Aug 2021, 3:49 PM
JaScript
JaScript - avatar
+ 4
chr() and ord() are inbuilt functions. I don't think you can do it without them.
3rd Aug 2021, 2:56 AM
David Ashton
David Ashton - avatar
+ 3
my code is close to the ones of JaScript, but it handles and keeps characters like punctuation: https://code.sololearn.com/c7RpPWEfFfsV/?ref=app
2nd Aug 2021, 4:47 PM
Lothar
Lothar - avatar
0
Sololearn-------input sOLOLEARN---- output
2nd Aug 2021, 3:23 PM
Disha Jain
0
Hi Disha! Here is my code by using characters instead of numbers. https://code.sololearn.com/cZFPxxYjLY46/?ref=app
2nd Aug 2021, 5:35 PM
Python Learner
Python Learner - avatar
0
Disha Jain Here are three possibilities, with only one meeting your needs: https://code.sololearn.com/cGPK0m7w9meI/?ref=app # Hope this helps
3rd Aug 2021, 7:23 AM
Calvin Thomas
Calvin Thomas - avatar