Really confused abt how to print?


#1



lloyd = {
"name": "Lloyd",
"homework": [90.0,97.0,75.0,92.0],
"quizzes": [88.0,40.0,94.0],
"tests": [75.0,90.0]
}
alice = {
"name": "Alice",
"homework": [100.0, 92.0, 98.0, 100.0],
"quizzes": [82.0, 83.0, 91.0],
"tests": [89.0, 97.0]
}
tyler = {
"name": "Tyler",
"homework": [0.0, 87.0, 75.0, 22.0],
"quizzes": [0.0, 75.0, 78.0],
"tests": [100.0, 100.0]
}
students=[lloyd,alice,tyler]
for student in students:
print"performance %s" % (student[lloyd])


Replace this line with your code.


#2

shall i define a function????


#3

lloyd = {
"name": "Lloyd",
"homework": [90.0,97.0,75.0,92.0],
"quizzes": [88.0,40.0,94.0],
"tests": [75.0,90.0]
}
alice = {
"name": "Alice",
"homework": [100.0, 92.0, 98.0, 100.0],
"quizzes": [82.0, 83.0, 91.0],
"tests": [89.0, 97.0]
}
tyler = {
"name": "Tyler",
"homework": [0.0, 87.0, 75.0, 22.0],
"quizzes": [0.0, 75.0, 78.0],
"tests": [100.0, 100.0]
}
students=[lloyd,alice,tyler]
def performance(lads):
for student in students:
return students
print performance(students)


#4

i rewrote the code console shows folowing
[{'quizzes': [88.0, 40.0, 94.0], 'tests': [75.0, 90.0], 'name': 'Lloyd', 'homework': [90.0, 97.0, 75.0, 92.0]}, {'quizzes': [82.0, 83.0, 91.0], 'tests': [89.0, 97.0], 'name': 'Alice', 'homework': [100.0, 92.0, 98.0, 100.0]}, {'quizzes': [0.0, 75.0, 78.0], 'tests': [100.0, 100.0], 'name': 'Tyler', 'homework': [0.0, 87.0, 75.0, 22.0]}]
None


#5

Which lesson are you on? Are you on 4. For the Record?
If so, I believe you're kind of overthinking it. You don't need a function. Just a loop through students is enough. And then you print the individual items such as for names, just do

for student in students:
    print student["name"]
    ...

in the loop.


#6

how is print format different from in this previous code below??/
prices= {
"banana":4,
"apple": 2,
"orange": 1.5,
"pear": 3
}
stock={
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15,
}
for key in prices:
print key
print "price: %s" % (prices[key])
print "stock: %s" % (stock[key])


#7

not getting the format for print


#8

Hmm? The print statement isn't that different. Here, you are printing a message that involved a string. Surely, you can do "price: " + (prices[key]) but it's preferred to have it formatted using "%s".

But when you are just printing a variable or an item in the dictionary, you just need to print it such as if you want to just print the prices without the message "price: ", then you just do

for key in prices:
    print prices[key]

#9

how abt this???
explain print for this aswell
animal_sounds = {
"cat": ["meow", "purr"],
"dog": ["woof", "bark"],
"fox": [],
}
print animal_sounds["cat"]


#10

It's the same as above....it's just that you are referring to a different key in a different dictionary...You're just printing the values for the key, 'cat".


#11

hey i got confused again
prices= {
"banana":4,
"apple": 2,
"orange": 1.5,
"pear": 3
}
stock={
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15,
}
for key in prices:
print key
print (prices[key])
print (stock[key])

in this key is inside the square bracket with dictionary name outside(which is written after for in for loop line)

lloyd = {
"name": "Lloyd",
"homework": [90.0,97.0,75.0,92.0],
"quizzes": [88.0,40.0,94.0],
"tests": [75.0,90.0]
}
alice = {
"name": "Alice",
"homework": [100.0, 92.0, 98.0, 100.0],
"quizzes": [82.0, 83.0, 91.0],
"tests": [89.0, 97.0]
}
tyler = {
"name": "Tyler",
"homework": [0.0, 87.0, 75.0, 22.0],
"quizzes": [0.0, 75.0, 78.0],
"tests": [100.0, 100.0]
}
students=[lloyd,alice,tyler]

for student in students:
print student["name"]
print student["homework"]
print student["quizzes"]
print student["tests"]
here student which is written after for is written outside the bracket


#12

help plzzzzzzzzzzz?..........


#13

plz respond???????????????????


#14

is some1 there??????????????


#15

plzzzzzzzzzzzzz rply????????????


#16

It's the same. Student is your dictionary no? It loops through your list of students which are tyler, lloyd and alice (the dictionaries). The keys are the tests, names, quizzes, homeworks!


#17

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.