Created
July 6, 2022 09:26
-
-
Save chuongmep/b2485439a9eb53528af78bd7cd40072d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Way 1 | |
a = "12354+656565865" | |
num1 = "" | |
num2 = "" | |
index = 1 | |
for i in range(len(a)): | |
if str.isdigit(a[i]): | |
num1 += a[i] | |
index += 1 | |
else: | |
for i in range(index,len(a)): | |
num2 += a[i] | |
break | |
print(num1,num2) | |
# Way 2 | |
a = "12354+656565865" | |
num1 = "" | |
num2 = "" | |
index = 1 | |
for i in range(len(a)): | |
if str.isdigit(a[i]): | |
num1 += a[i] | |
index += 1 | |
else: | |
print(index) | |
num2 = a[index:len(a)] | |
break | |
print(num1,num2) | |
# way 3 | |
a = "12354+65656-5865" | |
num1 = "" | |
num2 = "" | |
index = 1 | |
#regex match number | |
import re | |
print(re.findall(r'\d+', a)) |
a = "235+2*5*13/20+6*2"
import re
m = re.split(r'[^\d]',a)
print(m)
n = re.split(r'\d+',a)
def mul(m):
s = 1
for i in m:
s *= int(i)
return s
def div(m):
s = 1
for i in m:
s /= int(i)
return s
def sum(m):
s = 1
for i in m:
s += int(i)
return s
def sub(m):
s = 1
for i in m:
s -= int(i)
return s
def changetonum(str):
return int(str)
print(n)
Output :
m = ['235', '2', '5', '13', '20', '6', '2']
n = ['', '+', '', '', '/', '+', '*', '']
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
CALCULATOR