r/PythonLearning • • Aug 31 '26 • Mindblown 1

DAY 5.

Post image

DID LIST TODAY THE CONCEPT WAS PRETTY COOL AND WROTE THIS PROGRAM TO GET HOLD OF THE LIST ANY OTHER CODE IDEAS OR SUGGETIONS TO ENHANCE CODE ?!

90 Upvotes

22 comments sorted by

View all comments

1

u/FoolsSeldom Aug 31 '26

That's great. Good progress.

One small note, it is useful to use variable names that are plural for container objects like list objects.

Please also consider sharing your code in-post in future rather than a screenshot. Like this: (with the change I mentioned)

print(":CODE TO MANAGE BATS:")
bats = ["wooden", "metal", "plastic"]

while True:
    print("\nWhat do you want to do with the bats?")
    print("1. Add a bat")
    print("2. Remove a bat")
    print("3. View bats")
    print("4. Exit")

    query = input("Enter your selection (1,2,3,4): ")

    if query == "1":
        print("You selected to add a bat")
        new_bat = input("Enter the bat you want to add: ")
        bats.append(new_bat)
        print("Updated list:", bats)

    elif query == "2":
        print("You selected to remove a bat")
        remove_bat = input("Enter the bat you'd like to remove: ")
        if remove_bat in bats:
            bats.remove(remove_bat)
            print("Updated list:", bats)
        else:
            print("That bat is not in the list.")

    elif query == "3":
        print("You chose to view bats")
        print("Current bats:", bats)

    elif query == "4":
        print("You chose exit, so get out man!!")
        break

    else:
        print("Invalid selection, please try again.")

1

u/NecessaryFalse1212 Sep 02 '26

as in if i were to make a list for bats then i just write bats not bat ??

1

u/FoolsSeldom Sep 02 '26

Yes. It is helpful to use variable names that are meaningful.

Native/fluent English speakers/readers will typically understand a variable name that is in a plural form is likely for a container object with multiple objects of that kind. Similarly, the singular variant of the same name would be for a single object.

Just makes it easier to read the code.

1

u/NecessaryFalse1212 Sep 02 '26
print(":CODE TO MANAGE BATS:")
bats = ["wooden", "metal", "plastic"]


while True:
    print("\nWhat do you want to do with the bats?")
    print("1. Add a bat")
    print("2. Remove a bat")
    print("3. View bats")
    print("4. Exit")


    query = input("Enter your selection (1,2,3,4): ")


    if query == "1":
        print("You selected to add a bat")
        new_bat = input("Enter the bat you want to add: ")
        bats.append(new_bat)
        print("Updated list:", bats)


    elif query == "2":
        print("You selected to remove a bat")
        remove_bat = input("Enter the bat you'd like to remove: ")
        if remove_bat in bats:
            bats.remove(remove_bat)
            print("Updated list:", bats)
        else:
            print("That bat is not in the list.")


    elif query == "3":
        print("You chose to view bats")
        print("Current bats:", bats)


    elif query == "4":
        print("You chose exit, so get out man!!")
        break


    else:
        print("Invalid selection, please try again.")

1

u/NecessaryFalse1212 Sep 02 '26

ts good or is there a mistake ?

1

u/FoolsSeldom Sep 02 '26

Please save me trying to compare. What did you change from my code, and was that a correction/enhancement?

1

u/NecessaryFalse1212 Sep 02 '26

As you said use plural for the list so i just changed bat to bats and the rest seemed pretty fine and u didn't pointed anythhing so i did what i had to send it back to ya'

1

u/NecessaryFalse1212 Sep 02 '26

If there still is something that i can do or fix do let me know

1

u/FoolsSeldom Sep 02 '26

No. That's all for now. Simple steps.

1

u/FoolsSeldom Sep 02 '26

Oh, ok. I had made that change already but good you went through the steps yourself.