+ 1
How do I make output 1 when I input a
https://code.sololearn.com/cX4woQT1uib7/?ref=app For an upcoming project
8 Answers
+ 7
RocketLover ,
a more efficient method (as requested by you) is as described below:
> a simple way to get this *character to number* mapping can be done by using the *ord()* function.
ord() takes a character as argument, and returns its unicode / ascii code.
ord('a') returns 97
ord('b') returns 98
...
> if *a* should get *1*, we can subtract 96 from the number returned by ord()
# the code implementation could be:
char = input()
temp = ord(char) - 96
print(temp)
+ 7
RocketLover , Alin Ursulescu ,
> when we are using *input()* function, we do not need to use additionally the str() function.
> everything we input will be returned as *string* by default.
+ 2
x=str(input())
if x == "a":
print("1")
else:
print(x)
#works only with lowercase if you input uppercase it wont work
#if input isnt a lowercase "a" it Will output the input
#hope it helps
+ 1
Yeah,
x=input()
makes the same thing
+ 1
Alr thanks
+ 1
Took a while, tell me if there is a more efficient method
+ 1
I don't think I'm at that point yet, what lesson is that in?
0
All fixed, feel free if you want to use it