+ 1

How do I make output 1 when I input a

https://code.sololearn.com/cX4woQT1uib7/?ref=app For an upcoming project

17th Mar 2023, 7:20 PM
RocketLover
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)
18th Mar 2023, 5:37 PM
Lothar
Lothar - avatar
+ 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.
17th Mar 2023, 9:36 PM
Lothar
Lothar - avatar
+ 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
17th Mar 2023, 8:33 PM
Alin Ursulescu
Alin Ursulescu - avatar
+ 1
Yeah, x=input() makes the same thing
17th Mar 2023, 9:38 PM
Alin Ursulescu
Alin Ursulescu - avatar
+ 1
Alr thanks
18th Mar 2023, 12:03 PM
RocketLover
+ 1
Took a while, tell me if there is a more efficient method
18th Mar 2023, 4:04 PM
RocketLover
+ 1
I don't think I'm at that point yet, what lesson is that in?
19th Mar 2023, 10:44 AM
RocketLover
0
All fixed, feel free if you want to use it
18th Mar 2023, 4:04 PM
RocketLover