Python Forum
Open source project that a beginner could contribute to?
Thread Rating:
  • 2 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Open source project that a beginner could contribute to?
#10
(Apr-10-2017, 02:51 AM)teenspirit Wrote: Here is the Github Repo on that project: https://github.com/dariankbrown/The-5000 You should probably read through the forum post about it and the changes and updates it needs in the forum thread here: https://python-forum.io/Thread-Help-on-a...-the-needy Thanks in advance.

May I make a suggestion? I know this is simple and silly but I've learned to try to avoid even the simplest of bugs. In blocks of code such as:

def main():
    # Declaring the necessary variables and dictionary.
    large, small = 0, 0
    items = {}
    while True:
        # The following is our main menu that the user will see.
        userin = input(
            "Type 'i' to enter new items, 'r' to begin registering new families, or 't' to get currnet total and stats, e is to exit: ")
        if userin == 'i':
            food_items(items)
        elif userin == 'r':
            large, small = one_or_two(large, small)
        elif userin == 't':
            total(large, small, items)
        elif userin == 'e':
            total(large, small, items)
            final_total(large, small, items)
            break
        else:
            print('An unknown option: ', userin, ' has been entered. Please try the last entry again.')
When entering the string value, if a user enters it in capital letters it will give this traceback:

Error:
/usr/bin/python3.5 "/root/PythonProjects/External_Teachings/The 5000/the_5000.py" Type 'i' to enter new items, 'r' to begin registering new families, or 't' to get currnet total and stats, e is to exit: I An unknown option:  I  has been entered. Please try the last entry again. Type 'i' to enter new items, 'r' to begin registering new families, or 't' to get currnet total and stats, e is to exit
This is how I normally avoid this:

def main():
    # Declaring the necessary variables and dictionary.
    large, small = 0, 0
    items = {}
    while True:
        # The following is our main menu that the user will see.
        userin = input(
            "Type 'i' to enter new items, 'r' to begin registering new families, or 't' to get currnet total and stats, e is to exit: ")
        if userin.lower() == 'i':
            food_items(items)
        elif userin.lower() == 'r':
            large, small = one_or_two(large, small)
        elif userin.lower() == 't':
            total(large, small, items)
        elif userin.lower() == 'e':
            total(large, small, items)
            final_total(large, small, items)
            break
        else:
            print('An unknown option: ', userin, ' has been entered. Please try the last entry again.')
Or you can add an 'or' statement to the string saying...:

if userin == 'i' or 'I':
    food_items(items)
You can also avoid ValueErrors silently and still give the else statement that you used by using a try/except/else block so that it makes sure that the correct value must be entered in order to move forward... I guess it's doing this now but I find try/except/else blocks more efficient. Correct me if I am wrong?
Reply


Messages In This Thread
RE: Open source project that a beginner could contribute to? - by Low_Ki_ - Apr-10-2017, 03:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  My first project as a beginner lil_e 4 1,153 Feb-27-2023, 08:19 AM
Last Post: lil_e
  How do I open the Source code of a library? JaneTan 1 2,318 Aug-18-2021, 02:12 AM
Last Post: Larz60+
  Open for Python project(s) Python_User 8 3,357 Sep-10-2020, 07:45 PM
Last Post: Python_User
  Need help with this project / Beginner kurwa97 2 1,872 Nov-13-2019, 11:11 PM
Last Post: kurwa97
  Visual Studio Python 2.2 Source Project bobosamma 5 3,199 Oct-14-2019, 11:19 AM
Last Post: snippsat
  how to contribute our code/improvements to python pandas df..?? saikumarcheethirala 2 2,034 Jul-18-2019, 01:06 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020