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?
#13
(Apr-10-2017, 03:43 PM)Low_Ki_ Wrote: 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.')

Much better to do one single:
userin=lower(input("...........")
Otherwise, a dictionary of functions looks like a palatable option.

(Apr-10-2017, 03:43 PM)Low_Ki_ Wrote: Or you can add an 'or' statement to the string saying...:

if userin == 'i' or 'I':
    food_items(items)
Certainly not:
if userin == 'i' or userin =='I':
   food_items(items)
or
if userin in ['i','I']:
   food_items(items)
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply


Messages In This Thread
RE: Open source project that a beginner could contribute to? - by Ofnuts - Apr-11-2017, 10:06 AM

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