#🔒 help review first project pls

35 messages · Page 1 of 1 (latest)

wispy spindle
#

Hi this is my project which solves for 2 terms Boolean using string manipulation (I started learning python around 2 weeks ago)

it works but i find it hard to read the code since I made this through trial and error

what are things I can do to clean up the code for readability?
https://paste.pythondiscord.com/WNMA

cerulean shardBOT
#

@wispy spindle

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

wispy spindle
#

Enter the problem to solve: ab!c!d!e + !c!d!e!a!b
Simplify with single variable theorems
ab!c!d!e + !c!d!e!a!b = ab!c!d!e + !a!b!c!d!e

Factorising problem
ab!c!d!e + !a!b!c!d!e = !c!d!e(ab + !a!b)
!c!d!e(ab + !a!b)

Simplify terms within brackets
ab + !a!b = a XNOR b

Put simplified terms into bracket
!c!d!e(ab + !a!b) = !c!d!e(a XNOR b)

#

I enter boolean algebra with 2 terms

#

and it will show the steps and final expression

pulsar stirrup
#

!code kindly use code block

cerulean shardBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

wispy spindle
#

this part of code is the usage

pulsar stirrup
#

you could just used code block like said on the bot's message

wispy spindle
#

what does a code block do?
Sorry I'm new to this

fathom island
#
Enter the problem to solve: ab!c!d!e + !c!d!e!a!b
Simplify with single variable theorems
ab!c!d!e + !c!d!e!a!b = ab!c!d!e + !a!b!c!d!e

Factorising problem
ab!c!d!e + !a!b!c!d!e = !c!d!e(ab + !a!b)
!c!d!e(ab + !a!b)

Simplify terms within brackets
ab + !a!b = a XNOR b

Put simplified terms into bracket
wispy spindle
#

Oh

pulsar stirrup
#

you could try to make it OOP, to make the code cleaner and more readable

wispy spindle
#

thanks I'll try that

fathom island
#

I don't think 300 lines in one .py file is needed for this, you can maybe break it up into seperate files

#

And add classes

pulsar stirrup
#

well usualy i have something like 500 lines of code on single file...

fathom island
#

Depends on the project

#

Surely you can use a class for this - py def check_for_error(problem): terms = problem.split('+') #a,+,b,+ spacing = problem.split() problem_check = all(ch.isalpha() or ch.isdigit() or ch == '+' or ch == ' ' or ch == '!' for ch in problem) #check for valid characters if '(' in problem or ')' in problem: #declines brackets return 'Brackets are not accepted' if not problem.strip(): #declines empty input return 'please enter a valid input' if '!!' in problem: #checks for typos like !! return "double '!' is not allowed" if problem_check == False: #checks if characters are valid return 'Invalid input' if terms[0] in ('',' ') or terms[-1] in ('', ' '): #check if there are any equation errors, like +a or ++ return 'Terms are not accepted' if len(terms) > 2: #enforces only 2 operands return 'Maximum 2 terms' elif len(terms) < 2: return 'single' #returns single if only 1 term, for simplification if len(spacing) != 3: #checks for spacing return 'Please ensure correct spacing' return 'pass'

#

or loop list

pulsar stirrup
#

you can do parser with separate code that does the lexer and parsing

fathom island
pulsar stirrup
#

what do you mean?

fathom island
#

parser with separate code that does the lexer and parsing

pulsar stirrup
#

huh?

fathom island
#

what do u mean

fathom island
pulsar stirrup
#

its more like this

tokens = lexer(data)
output = parser(tokens)
fathom island
#

I see

fathom island
cerulean shardBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.