What's new

Help Replace parenthesis

vien3211

Eternal Poster
Established
Joined
Aug 9, 2016
Posts
830
Reaction
73
Points
314
Pa help naman po i replace ung parenthesis using python

Ganito po ung input: D / )C * B + A(

Dapat po maging ganito ung output: D / (C * B + A)
 
You do not have permission to view the full content of this post. Log in or register now.
na try ko na po siya. ganito po ba?
1665582737001.png
 

Attachments

First, replace the first parenthesis then remove the last char then append closing parenthesis

Code:
>>> x = 'D / )C * B + A('
>>> y = x.replace(')', '(')[:-1] + ')'
>>> y
'D / (C * B + A)'
Hello sir! Ask ko lang po kung ito po ung ginamit niyo [:-1] para ma remove ung last char?
 

Similar threads

Back
Top