0

So I am creating a program that allows the user to input values into sets a-f and you for the universal set. I want to collect their input and have it outputted in a specific format. For example:

Which set would you like to edit? (a-f) or universe (u) >> a
Editing set a. Please enter values, when finished, enter 'stop' 

give me something >>> a
I have added a to the set a.

give me something >>> b
I have added b to the set a.

give me something >>> c
I have added c to the set a.

give me something >>> ab
I have added ab to the set a.

give me something >>> ac
I have added ac to the set a.

give me something >>> bc
I have added bc to the set a.

give me something >>> abc
I have added abc to the set a.

give me something >>> stop
a = ["a", "b","c","ab","ac","bc","abc"]

Instead, this is what happens:

Welcome to Logica!

Which set would you like to edit? (a-f) or universe (u) >> a
Editing set a. Please enter values, when finished, enter 'stop' 

give me something >>> a
I have added a to the set a.

give me something >>> b
I have added b to the set a.

give me something >>> c
I have added c to the set a.

give me something >>> ab
I have added ab to the set a.

give me something >>> ac
I have added ac to the set a.

give me something >>> bc
I have added bc to the set a.

give me something >>> abc
I have added abc to the set a.

give me something >>> stop
['a', 'b', 'c', 'a', 'b', 'a', 'c', 'b', 'c', 'a', 'b', 'c']

As you can see above, my code separates each letter when inputted. Is there a way to get my desired output in the same format as I specified above? Here is my code that I have right now:

class Logica:

    def start(self):
        # welcome user
        print("Welcome to Logica!\n")

        # seek user input
        # a,b,c,d,e,f = [],[],[],[],[],[]
        self.a = []
        self.b = []
        self.c = []
        self.d = []
        self.e = []
        self.f = []
        self.u = [] # universal set

        setEdit = input("Which set would you like to edit? (a-f) or universe (u) >> ")
        if setEdit == "a":
            print("Editing set a. Please enter values, when finished, enter 'stop' \n")
            entry = ""
            while True:
                entry = input("give me something >>> ")
                if entry != "stop": 
                    self.a += entry
                    print("I have added " + entry + " to the set a.\n")
                else:
                    # display values in a
                    aa = []
                    for response in self.a:
                        # print(str(response) + ",")
                        aa += str(response)
                    print(aa)
                    a.whatNow()

        elif setEdit == "b":
            print("Editing set b. Please enter values, when finished, enter 'stop' \n")
            entry = ""
            while True:
                entry = input("give me something >>> ")
                if entry != "stop": 
                    self.b += entry
                    print("I have added " + entry + " to the set b.\n")
                else:
                    # display values in b
                    bb = []
                    for response in self.b:
                        # print(str(response) + ",")
                        bb += str(response)
                    print(bb)
                    a.whatNow()

    def whatNow(self):
        print("Here are your options: \n")
        exit(0)       



if __name__ == "__main__":
    a = Logica()
    a.start()

1 Answer 1

1

A little hard to understand your code, Change your while loop to:

while True:
    entry = input("give me something >>> ")
    if entry != "stop":
        self.a.append(entry)
        print("I have added " + entry + " to the set a.\n")
    else:
        # display values in a
        aa = []
        for response in self.a:
            # print(str(response) + ",")
            aa.append(response)
        print(aa)
        a.whatNow()

and b,too.

Sign up to request clarification or add additional context in comments.

2 Comments

So if I want to print the list 'a' for example to show what is inside of it, when I do "print(a)" or "print(str(a))" it gives me the memory address, how can I get it to where it'll give me the actual values stored in list a?
@FaiqAshraf Maybe you need to use print(self.a).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.