Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7929321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:02:01+00:00 2026-06-03T20:02:01+00:00

The goal is to create a program which will effectively let the user create

  • 0

The goal is to create a program which will effectively let the user create boolean logic statements (not started ), store those expressions, access them (expression_menu), build them (setup_table) and then evaluate them (truth) then finally test them (in another module).

Given all that, which is a fairly large project for my skills. I’m stuck on how to organize everything. I feel like i might want to be moving towards using classes because it might be easier to keep track of attributes…

Immediately however my problem is that how to transfer around the boolean logic statements, obviously on line 29 i’ll get a syntax error because x is undefined (the snippet of code only makes sense in lines 11 through 15.

How can i organize my code here to better suit my goal

def setup_table(variables=2):
    return (list(itertools.product(range(2), repeat = variables)))

def truth(variables=None,expression=None):
    truth_table = []
    for x in setup_table(variables):
        if expression:
            x.append(1)
        else:
            x.append(0)
        truth_table.append(x)
    return truth_table

def expression_menu():
    expression = input('''
    choose your expression:
    1. if ((p and q) or (p or q)) and not(r or not q):
    2. if (p or r) or (q and s):
    3. if (p or r) and ( q or (p and s))

    Expression: ''')
    table = None
    if int(expression) == 1:
        table = truth(variables = 3, expression =((x[0] and x[1]) or (x[0] or x[1])) and not (x[
    print(table)

if __name__ == "__main__":
    import itertools
    expression_menu()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:02:03+00:00Added an answer on June 3, 2026 at 8:02 pm

    You could make your boolean expression into a function.

    So:

    table = truth(variables = 3, expression = lambda x: (x[0] and x[1]))
    

    or:

    def expression(x):
        return x[0] and x[1]
    table = truth(variables = 3, expression = expression)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The goal is to create a mock class which behaves like a db resultset.
My goal is to create an efficient structure to store the most relevant entries
Goal To use a CREATE TYPE statement in HSQLDB 2.0.0 to create a user-defined
I am currently working on a program which accepts a user input through the
The goal behind this question is to create a portable Windows script/program that would
Duplicate: PHP validation/regex for URL My goal is create a PHP regex for website
my goal is to create a sort of Javascript library, if you could call
My goal is to create something like 1Up.com has where website viewers gain Experience
My Goal: i want to create an horizontal list of images. when mouse is
Im trying to create a moving back ground. My goal is to have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.