Python Forum
printing data from dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
printing data from dictionary
#4
(Nov-20-2017, 03:31 PM)heiner55 Wrote:
def data():
    people = int(input("How many individuals are attending? "))
    attendees = {}
    for i in range(people):
        name = str(input('Please enter name: '))
        amount = int(input('Number of toys donated:'))
        attendees[name] = amount
    return attendees

def print_data():
    attendees = data()

    print('Level 1')
    for i in attendees:
        if attendees[i] > 20:
            print(i, attendees[i])

    print('Level 2')
    for i in attendees:
        if attendees[i] <= 20:
            print(i, attendees[i])

print_data()

Thanks for your reply. While this gets me closer, it also only prints on entry. When I modify my code as suggested, it only allows me to enter one name before it prints the name/level. So if I entered 3 attendees would be attending, it only gives me the chance to enter the first name and then immediately moves to the second function to print the name.

This also makes me think that I want to modify it further to only print the level name if there are entries that apply. In other words, if there are no entries that would fall into level 2, then it should not print the level 2 header.
Reply


Messages In This Thread
printing data from dictionary - by kiki1113 - Nov-20-2017, 02:37 PM
RE: printing data from dictionary - by buran - Nov-20-2017, 03:31 PM
RE: printing data from dictionary - by heiner55 - Nov-20-2017, 03:31 PM
RE: printing data from dictionary - by kiki1113 - Nov-20-2017, 03:52 PM
RE: printing data from dictionary - by heiner55 - Nov-20-2017, 04:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Read data from a CSV file in S3 bucket and store it in a dictionary in python Rupini 3 7,074 May-15-2020, 04:57 PM
Last Post: snippsat
  Why is this function printing the number of keys in a dictionary? mafr97 5 3,122 Sep-17-2019, 06:19 AM
Last Post: perfringo
  Presenting data from a dictionary in a basic table ijosefson 3 3,359 Oct-16-2017, 04:13 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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