So I'm writing a program (A sort of "custom if statement") that checks if your input is true or false. This is the script I have right now:
v=line[3:] # Remove "if " from the line, so you only have the question and the consequence
i=v.split(': ') # Make a list with the first item being the question and the second item being the consequence.
for r in i:
if r==i[1]: # Check which item in the list is the question and which is the consequence
c=r
question=i[0]
consequences=c.split(' | ')
for x in consequences:
self.consequences+=f'\n{x}' # Create a variable with all of the consequences, each in one line
Answer=False # reate the Answer variable with the default value False
exec(f"def checkVal():\n global Answer\n if {question}==True:\n Answer=True\n else:\n Answer=False\ncheckVal()") # Check if the question is true or false
if Answer==True:
print("True!")
else:
print("False!") # Finally check if the question is true or not and if it is, print "True!" and if it's not, print "False!"
I'm expecting this to work, but then when i input something that's true, for example: __name__=="__main__", so my input looks like this:
if __name__=="__main__": print("Hello!")
this is the output:
False!
How do I fix this so it prints it accurately?
Aucun commentaire:
Enregistrer un commentaire