Nov-20-2017, 02:37 PM
Quote:NOTE: modifying my questions below as I was able to fix the issue with my original post but am now having additional problems.
I'm trying to write code that will collect the number of individuals attending an event. Based on the number of people entered, I will ask that many times a) the name of the individual, b) the number of toys they have donated. I want the information to be entered into a dictionary which i will pass to another function. The second function will select individuals who have donated more than 20 toys and print their name and the number of toys the donated as "level 1" and then everyone else as "level 2".
I've checked to make sure that the data is being passed from one function to another correctly. I'm having issues printing the donation amount without the []. Also, it keeps printing the level above each entry instead of listing the entries underneath the level. In other words, I'm trying to get:
Level 1
Selena Gomez 50
Beyonce 40
Level 2
Will Smith 5
What am I doing wrong?
Here is my code:
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() for i in attendees: if attendees[i][0] > 20: print('Level 1') print(i, attendees[i]) else: print('Level 2') print(i, attendees[i]) print_data()And here is my output:
Error:How many individuals are attending? 3
Please enter name: Will Smith
Number of toys donated:5
Please enter name: Selena Gomez
Number of toys donated:50
Please enter name: Beyonce
Number of toys donated:40
Level 2
Will Smith [5]
Level 1
Selena Gomez [50]
Level 1
Beyonce [40]