+ 1

Convert to int even with symbol occurring

This is my code import re i=input("Enter text:") ot=0 ctl=i.split() print(ctl) if re.findall(r"--\d",i): ot=int(i) print(ot) What I need to do is that I want to convert to int even with this symbol occurring getting no errors. How can I do it ?

30th Nov 2022, 9:20 AM
U14known
U14known - avatar
20 Answers
+ 10
U14known , since the input is just a number, or a a number with 2 leading *HYPHEN MINUS*, i don't think that we need to use regex. it could be done like: https://code.sololearn.com/c0uzsPoW7Ie0/?ref=app
30th Nov 2022, 3:04 PM
Lothar
Lothar - avatar
+ 6
mmaos QQQ , to create a new question you can do: > go to the *create section* (bottom of page) > select *discuss* (top of page) > click *+ new post* button
2nd Dec 2022, 12:38 PM
Lothar
Lothar - avatar
+ 5
U14known , Lochard , i have added also a version to the code in my first post that can handle multiple inputs of numbers.
2nd Dec 2022, 12:56 PM
Lothar
Lothar - avatar
+ 4
U14known , pease make an input sample and what you are expecting as output.
30th Nov 2022, 10:38 AM
Lothar
Lothar - avatar
+ 4
U14known , the "--" that you have use are 2 *HYPHEN MINUS* (unicode id / ascii 45). is this what you have meant?
30th Nov 2022, 10:58 AM
Lothar
Lothar - avatar
+ 3
U14known , I improved your code a bit I hope this is what you wanted import re, string letter=list(string.ascii_lowercase) str_in = input() cap = str_in[:2] == "--" sp = int(re.findall(r"\d+",str_in)[0])-1 if cap: print(letter[sp].upper()) else: print(letter[sp]) https://code.sololearn.com/cncy8PiCii50
30th Nov 2022, 12:04 PM
SoloProg
SoloProg - avatar
+ 2
https://code.sololearn.com/cB7wkbqOzyqZ/?ref=app
2nd Dec 2022, 6:38 AM
Lochard
Lochard - avatar
+ 1
Convert to int even with symbol occurring This is my code import re import string st=list(string.ascii_lowercase) i=input("Enter text:") ot=0 ctl=i.split() print(ctl) if re.findall(r"\--\d",i): ot=int(i) print(st[ot]) Input:12 Output:l
30th Nov 2022, 10:46 AM
U14known
U14known - avatar
+ 1
The output is a list of int though. https://code.sololearn.com/cLe5suunzki8/?ref=app
30th Nov 2022, 11:05 AM
Lochard
Lochard - avatar
+ 1
Thank you everyone for answering and helping. There's just one final issue Try to write the code like this: Input:12 --13 Output: l M This should give me 2 letters .
2nd Dec 2022, 4:23 AM
U14known
U14known - avatar
+ 1
Thank you all for helping. Thank you Lochard. Your code worked
2nd Dec 2022, 7:07 AM
U14known
U14known - avatar
0
When I execute this code, because the -- is here the letter should be capital
30th Nov 2022, 10:47 AM
U14known
U14known - avatar
0
Nope. I mean I've written number 12 as mentioned in the input but added -- before it. So the input now will be like this Without -- input:12 Output:l With -- input:--12 Output:L
30th Nov 2022, 11:05 AM
U14known
U14known - avatar
30th Nov 2022, 11:20 AM
U14known
U14known - avatar
0
How to add question? I can not see button to add that
1st Dec 2022, 10:25 PM
mmaos QQQ
mmaos QQQ - avatar
0
mmaos QQQ do you know how to create a code ?
2nd Dec 2022, 4:00 AM
U14known
U14known - avatar
0
Or any number of letters I need
2nd Dec 2022, 4:24 AM
U14known
U14known - avatar
0
Input 12
2nd Dec 2022, 10:24 AM
Gift Mulubwa
Gift Mulubwa - avatar
2nd Dec 2022, 1:20 PM
U14known
U14known - avatar
0
Make sure to read the comments, they will help
2nd Dec 2022, 1:20 PM
U14known
U14known - avatar