Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a function called check_validity in python without import that will go th

ID: 3732759 • Letter: C

Question

Create a function called check_validity in python without import that will go through a given formula which is a string and return whether or not the function is valid.

Here are some valid formulas (shown as Python strings).

- represents not

* represents and

+ represents or

• "x"
• "-y"
• "(x*y)"

• "((-x+y)*-(-y+x))"

Here are some strings that are not formulas.

• "X" uppercase letter
• "x*y" no parentheses
• "-(x)" extraneous parenthes
• "(x+(y)*z)" mismatched parentheses

def check_validty("x"): >>> Valid

Explanation / Answer

Little bit code modification is here and please use below and let me know if any other information required in this code:

def check_validity(x):

result = ""  

if x == "x":

result = "valid"

if x == "X":

result = "X is uppercase and it not vlaid formula"

if x == "-y":

result = "valid"

if x == "(x*y)":

result = "valid"

if x == "x*y":

result = "No Parenthesis in formula, invalid formula"

if x == "(-x+y)*-(-y+x)":

result = "valid"

if x == "(x+(Y)*z":

result = "mismatched parenthesis"

return result

  

x = input("Please enter valid formula")

response = check_validity(x)

print(response)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote