Jun-25-2020, 03:21 PM
In this challenge you will be given a relation between two numbers, written as a string.
Here are some example inputs:
"2 = 2", "8 < 7", "5 = 13", "15 > 4"
Write a function that determines if the relation is True or False.
Examples
is_it_true("2 = 2") ➞ True
is_it_true("8 < 7") ➞ False
is_it_true("5 = 13") ➞ False
is_it_true("15 > 4") ➞ True
Notes
Tests will only have three types of relations: =, >, and <
Many approaches work here, but the eval() function is particularly useful!
Here is my code. It doesn't work. It passes nearly every test. In the message box, I get this error: ERROR: Traceback:
in <module>
in is_it_true
File "<string>", line 1
2=2
^
SyntaxError: invalid syntax
Here is my code:
Here are some example inputs:
"2 = 2", "8 < 7", "5 = 13", "15 > 4"
Write a function that determines if the relation is True or False.
Examples
is_it_true("2 = 2") ➞ True
is_it_true("8 < 7") ➞ False
is_it_true("5 = 13") ➞ False
is_it_true("15 > 4") ➞ True
Notes
Tests will only have three types of relations: =, >, and <
Many approaches work here, but the eval() function is particularly useful!
Here is my code. It doesn't work. It passes nearly every test. In the message box, I get this error: ERROR: Traceback:
in <module>
in is_it_true
File "<string>", line 1
2=2
^
SyntaxError: invalid syntax
Here is my code:
def is_it_true(relation): if eval(relation) is True: return True else: return FalseWhat am I missing here??? I'm so close!