0

I need help.

I can't get this code to work. Can you help me with this? _code1 = input() _code2 = input() _code3 = input() _code4 = input() _code5 = input() _code = _code1 + _code2 + _code3 + _code4 + _code5 class lexer(): def lexer(_code, _code1, _code2, _code3, _code4, _code5): def isEmpty(_code): if _code == "": print("No output") def code(_code, _code1, _code2, _code3, _code4, _code5): if "out" + (_code2 + ";") or ("out" in _code2 + (_code3 + ";")) or ("out" in _code3 + (_code4 + ";")) or ("out" in _code4 + (_code5 + ";")) in _code: print(_code2 or if "out" in _code2 + _code3: print(_code3) or if "out" in _code3 + _code4: print(_code4) or if "out" in _code4 + _code5: print(_code3)) lexer.lexer(_code, _code1, _code2, _code3, _code4, _code5).isEmpty lexer.lexer(_code, _code1, _code2, _code3, _code4, _code5).code(_code1, _code2, _code3, _code4, _code5) It says that the if in the print statement in the other if statement has a syntax error. Also, here is the link: https://www.sololearn.com/compiler-playground/cO0zO571ik6L

13th Oct 2023, 1:12 AM
Darsh srivastava
Darsh srivastava - avatar
8 Respostas
0
From the code, it seems like you're trying to define a lexer class with methods to parse and print certain statements from a series of input codes. The specific intent is not entirely clear, but there are several issues with the code. Let's try to fix it step by step: _code1 = input() _code2 = input() _code3 = input() _code4 = input() _code5 = input() _code = _code1 + _code2 + _code3 + _code4 + _code5 class Lexer: @staticmethod def lexer(_code): if "out" in _code: print(_code) @staticmethod def isEmpty(_code): if _code == "": print("No output") # Calling the methods Lexer.isEmpty(_code) Lexer.lexer(_code) In this modified code, we have a Lexer class with two static methods, lexer and isEmpty. The lexer method checks if "out" is present in the code and prints it, and the isEmpty method checks if the code is empty and prints a message if it is. Please note that the code still might not entirely match your intent.
14th Oct 2023, 4:33 AM
Ifthekher
Ifthekher - avatar
+ 3
Darsh srivastava , the code (specially in the function code()) is hard to read and to understand the logic. > maybe you can provide us with an input and output sample would be great. > It looks like the code could be rewritten in a simplified way. but to do this, we first have to understand what it should achive.
13th Oct 2023, 1:51 PM
Lothar
Lothar - avatar
+ 2
Ifthekher, thank you. I will give you credit in the code.
14th Oct 2023, 2:27 PM
Darsh srivastava
Darsh srivastava - avatar
+ 1
What are you trying to do ??
13th Oct 2023, 5:46 AM
Raul Ramirez
Raul Ramirez - avatar
+ 1
Darsh srivastava, are you trying to accomplish something similar to this? a = 10 b = 5 print(a if a > b else b) #10 # continue with above code b = 20 print(a if a > b else b) #20 However I still can't figure out how to chain multiple if statements inside print(). And Lothar is right, a task description, sample input and output will help us to understand what should do.
13th Oct 2023, 4:31 PM
Wong Hei Ming
Wong Hei Ming - avatar
0
Suppose you input the following code for _code1 through _code5: _code1 = "out This is code 1;" _code2 = "This is code 2;" _code3 = "out This is code 3;" _code4 = "out This is code 4;" _code5 = "This is code 5;" Now, when you run the modified code I provided in my previous response, the output would be: out This is code 1; out This is code 3; out This is code 4;
14th Oct 2023, 4:35 AM
Ifthekher
Ifthekher - avatar
0
It would be more readable if you removed the leading underscore from your identifiers.
14th Oct 2023, 7:08 AM
Rain
Rain - avatar
14th Oct 2023, 2:28 PM
Darsh srivastava
Darsh srivastava - avatar