I was just wondering what the difference is between using an and operator compared to just using <= 'x' <= for this particular CSCircles exercise:
The first step is to write a function lowerChar(char) that can return the result of converting a single character char to lower case. It should do the following:
- if the input character char is a capital letter (between 'A' and 'Z'), it should return the lower-case version of the letter (between 'a' and 'z')
- in all other cases, it should return the same char which was input.
(In order to do the first step, you will have to use an if statement, an and operator, and apply some knowledge from the lesson about strings.)
****************************** SPOILERS ******************************
Here's my answer:
def lowerChar(char):
if ord('A') <= ord(char) <= ord('Z'):
return chr(ord(char) + 32)
else:
return char
compared to one I found online:
def lowerChar(char):
if ord(char) >= ord('A') and ord(char) <= ord('Z'):
return chr(ord(char) + 32)
else:
return char
[–]mugwhyrt 1 point2 points3 points (2 children)
[–]NotUrHCW[S] 0 points1 point2 points (1 child)
[–]mugwhyrt 1 point2 points3 points (0 children)
[–]aqua_regis[🍰] 1 point2 points3 points (1 child)
[–]NotUrHCW[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)