🔒 Closed Replace parenthesis

Status
Not open for further replies.

vien3211

Honorary Poster
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.webp
 
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?
 
Status
Not open for further replies.

About this Thread

  • 4
    Replies
  • 676
    Views
  • 3
    Participants
Last reply from:
vien3211

Online now

Members online
602
Guests online
996
Total visitors
1,598

Forum statistics

Threads
2,277,844
Posts
28,979,216
Members
1,229,107
Latest member
worldteens2021
Back
Top