Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Str problem, not counting
#5
How about a dictionary?
count = {'a':0, 'b':0, 'c':0}
for _ in range(1, 11):
    choice = input('Please choose a char from a to c - ')
    if choice in count.keys():
        count[choice] += 1

for key, value in count.items():
    print(key, count)
If you have a bunch of variables with similar names it often means you should be using a collection.
Reply


Messages In This Thread
Str problem, not counting - by Hann - Jul-28-2020, 01:37 PM
RE: Str problem, not counting - by hussainmujtaba - Jul-28-2020, 01:47 PM
RE: Str problem, not counting - by Hann - Jul-28-2020, 02:07 PM
RE: Str problem, not counting - by faaadz275 - Jul-28-2020, 02:39 PM
RE: Str problem, not counting - by deanhystad - Jul-28-2020, 03:46 PM
RE: Str problem, not counting - by Hann - Jul-28-2020, 06:23 PM
RE: Str problem, not counting - by deanhystad - Jul-28-2020, 07:10 PM
RE: Str problem, not counting - by Hann - Jul-29-2020, 07:58 AM

Forum Jump:

User Panel Messages

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