Python Forum
Need help with a code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with a code
#5
Whenever you get stuck getting started on something like this it's a good idea to write out the steps in plain language and then convert it into python. This is called pseudo-code and it separates the logic from the syntax and lets you focus on just the logic. In your case it would look something like this:

Define a letter_counter function that takes in a string parameter called word_in:
__Create an empty dictionary to hold the results called result
__Loop through every letter in word_in:
____If letter is in the keys of the result dictionary:
______Add 1 to that key's value
____If not:
______Create a new key called letter and set its value to 1
__Return the result dictionary to end the function

Now you can look over the pseudo-code and start picking out the variables and functions you will need to translate it into python.

Note that I am creating a function since it's good programming. If you haven't learned functions yet just ignore the first and last line of the pseudo-code.

See how far you can get and, of course, read up on python dictionary methods if you haven't already. Wink
"So, brave knights, if you do doubt your courage or your strength, come no further, for death awaits you all with nasty, big, pointy teeth!" - Tim the Enchanter
Reply


Messages In This Thread
Need help with a code - by saratha - Aug-06-2020, 10:57 AM
RE: Need help with a code - by buran - Aug-06-2020, 11:14 AM
RE: Need help with a code - by pyzyx3qwerty - Aug-07-2020, 05:03 PM
RE: Need help with a code - by deanhystad - Aug-07-2020, 05:45 PM
RE: Need help with a code - by Marbelous - Aug-07-2020, 06:01 PM
RE: Need help with a code - by saratha - Aug-24-2020, 12:50 PM

Forum Jump:

User Panel Messages

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