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?
#11
This is incorrect:
if userin == 'i' or 'I':
    food_items(items)
It will always evaluate to True. To do this correctly you can do:
if userin == 'i' or userin == 'I':
or:
if userin in ('i', 'I'):
Using the lower method is better when dealing with case insensitive searches. It is best to use lower once:
userin = input('blah blah blah').lower()
if userin == 'i':
    ...
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#12
I am working on fixing a lot of bugs, you have a zero division error from the main menu when you select the "t" option with no registered families, also a few more that I will be working on when options are selected in different orders. I will post a pull request on git when finished.

(Apr-10-2017, 04:51 PM)ichabod801 Wrote: This is incorrect:
if userin == 'i' or 'I':
    food_items(items)
It will always evaluate to True. To do this correctly you can do:
if userin == 'i' or userin == 'I':
or:
if userin in ('i', 'I'):
Using the lower method is better when dealing with case insensitive searches. It is best to use lower once:
userin = input('blah blah blah').lower()
if userin == 'i':
    ...

Thank you, I will re-write again. I am still new to python but I feel that helping others learn is the best way for me to learn
Reply
#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
#14
Thanks for the help everyone! I really appreciate it. You have marked off almost my complete list of bugs already. I wanted there to be no bugs in getting the inputs and the values for everything before i start working on the part of the program that will calculate what to give each person and adjust the predictions. There is one last bug that i noticed to work out. When you are inputing whether to do another item or to go back to the main menu in our food_items(items) function, if you enter an unrecognized character it prompts you to start entering another item. I'm not quite sure why it does this, I understand that it is going to the top of the defined loop, which gives you that prompt, but I'm not quite sure how to fix it. I'm sure it would be easy enough for someone more experienced than myself to figure out how to fix the logic in that loop, but i have tried a few different ways with what I know and I just cant seem to get it right. So if anyone can help me on that, that is what I need to start working on the functional part of the program. I talked to Scott, unfortunately he has to turn those ever so valuable sheets of paper in to the food bank that distributes the corporate excess that goes into this distribution. I will do my best to figure out which company it is and get those sheets, but it could take a while.
Reply
#15
I'm not sure for which part of the code you are talking about but this is where try/except comes handy.

See post #37.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#16
@teenspirit, you should really continue conversation about your script in your original thread or create a new one rather than hijacking this one.  New readers of this thread will have no idea what you are talking about and therefore will not be able to help you out.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#17
I feel like we should class some of the functions into modules to import that way we can have a more clean main.py script

(Apr-12-2017, 06:30 PM)sparkz_alot Wrote: @teenspirit, you should really continue conversation about your script in your original thread or create a new one rather than hijacking this one.  New readers of this thread will have no idea what you are talking about and therefore will not be able to help you out.

yes sir. i do apologize for carrying it on this thread
Reply


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