Python Forum
Need help with a code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with a code
#6
(Aug-07-2020, 05:45 PM)deanhystad Wrote: This is a really simple task. You think it is hard because you don't know how to write the program. Yet.

Start with solving the problem, not writing the program. I give you a piece of paper and a pencil. I tell you to write down the word "abracadabra".

Tell me all the letters that appear in the word.
Tell me how many times each letter appears in the word.

Were you able to accomplish the task? Was it hard?

Now translate the algorithm you used into a Python program. What was the first thing you did?

Step 1. Write down the word.
How do you enter data, like words and numbers, into a Python program? Are you going to get the word from a file or does the user type the word at the keyboard. Solve this problem first and verify you get the word by printing it out. Testing the code you wrote to verify it works is "unit testing".

Step 2. Make a list of the letters. How did you do that step with pencil and paper? The assignment says your result should be a dictionary. Find out how dictionaries work and what is the dictionary equivalent of "making a list of the letters". Print the dictionary and verify it contains all the letters that appear in the word. Another unit test!

Step 3: Count how many times each letter appears. How did you do that with pencil and paper. Dictionaries map a value to a key. You are interested in letters and counts. Which do you think is the best choice for a key? When a letter appears more than once, how do you record that information in your dictionary? When this step is complete print the dictionary again to verify the letter counts are correct. More unit testing!

Step 4: Print each letter that repeats itself. What does this mean? Does that mean letters that appear more than once in the word? We have a dictionary of letters and the number of times each letter appears. How can that be used to solve this last step.

See, not that bad. Only 4 little steps.

Step 4:
thanks a lot ! it helped me :)
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