Python Forum
Feedback on my first program?
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Feedback on my first program?
#3
To add a small comment, you have many chains of if, elif, elif... without a final else.
This can do debugging your code really painful, as some function will silently do nothing.
In a set of if/elif conditions if the final option is something that you do not expect is a good idea to raise an error or at least inform the user:
    if answer in ('y', 'yes'):
        guessGame()
    elif answer in ('n', 'no'):
        wutNow()
    else:
        print(f'I do not understand {answer}. Please input yes or no')
If your real intention is to do nothing you can add a pass statement:
    if answer in ('y', 'yes'):
        guessGame()
    elif answer in ('n', 'no'):
        wutNow()
    else:
        # Ignore the user and continue with the program...
        pass
In this way is clear that your intention is to do nothing, not that you forgot a condition. Obviously this is important for nested if/elif. You can do the same for a normal if/else, but usually is not necessary.
Reply


Messages In This Thread
Feedback on my first program? - by jibby - Jun-12-2018, 04:20 AM
RE: Feedback on my first program? - by perfringo - Jun-12-2018, 06:35 AM
RE: Feedback on my first program? - by jibby - Jun-12-2018, 10:40 AM
RE: Feedback on my first program? - by killerrex - Jun-12-2018, 08:47 AM
RE: Feedback on my first program? - by perfringo - Jun-14-2018, 06:38 AM
RE: Feedback on my first program? - by jibby - Jun-18-2018, 04:09 AM
RE: Feedback on my first program? - by WolfWayfarer - Jul-16-2018, 08:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  First program feedback xyzabc12310000 2 3,477 May-20-2018, 05:06 PM
Last Post: xyzabc12310000
  I need some feedback on this program tannishpage 3 3,239 Mar-22-2018, 05:31 AM
Last Post: tannishpage

Forum Jump:

User Panel Messages

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