+ 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 ?
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
+ 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
+ 4
U14known ,
pease make an input sample and what you are expecting as output.
+ 4
U14known ,
the "--" that you have use are 2 *HYPHEN MINUS* (unicode id / ascii 45). is this what you have meant?
+ 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
+ 2
https://code.sololearn.com/cB7wkbqOzyqZ/?ref=app
+ 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
+ 1
The output is a list of int though.
https://code.sololearn.com/cLe5suunzki8/?ref=app
+ 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 .
+ 1
Thank you all for helping.
Thank you Lochard. Your code worked
0
When I execute this code, because the -- is here the letter should be capital
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
0
How to add question? I can not see button to add that
0
mmaos QQQ do you know how to create a code ?
0
Or any number of letters I need
0
Input 12
0
https://code.sololearn.com/cr8O71LhYPAl/?ref=app
This is my code.
0
Make sure to read the comments, they will help
Hot today
What's wrong? :(
1 Votes
Why won't my image display
0 Votes
I have made a calculator in which my % (Percentage) not work correctly for 100%50 or 100%20.
2 Votes
How the answer is 50?
0 Votes
Number of Ones ( C++ ) question!
1 Votes