0% found this document useful (0 votes)
9 views1 page

Try

The document contains a Python script that processes a string input using regular expressions to manipulate parentheses and alphabetic characters. It splits the input based on parentheses and alphabetic characters, modifies them, and then evaluates the resulting expressions. The script also demonstrates the evaluation of a specific string expression.

Uploaded by

maddison omi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Try

The document contains a Python script that processes a string input using regular expressions to manipulate parentheses and alphabetic characters. It splits the input based on parentheses and alphabetic characters, modifies them, and then evaluates the resulting expressions. The script also demonstrates the evaluation of a specific string expression.

Uploaded by

maddison omi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

# -*- coding: utf-8 -*-

"""
Created on Sat Jan 18 13:00:11 2020

@author: VelsTech
"""
"""l = [1,2,3,4]
l = list(map(lambda x: x+10,l))
print(l)"""
import re
s=input()

c = re.split("\(",s)
r = re.findall("\(",s)
print(c,r)
res = ''
for i in range(len(r)):
if(c[i][-1].isdigit()):
r[i]='*'+r[i]
else:
r[i]='+'+r[i]
res += c[i]+r[i]
res+=c[-1]

s=res
print(s)

c = re.split("[a-z]+",s)
r = re.findall("[a-z]+",s)
print(c,r)
res = ''
for i in range(len(r)):
res += c[i]+"\'"+r[i]+"\'"
res+=c[-1]

print(res)
print(eval(res))

s = "2*(\'a\'+(3*(\'b\')))"
print(s)
print(eval(s))

You might also like