| | |
help with functions
![]() |
•
•
Join Date: Oct 2005
Posts: 4
Reputation:
Solved Threads: 0
I have this function that takes info from two lists, and produces a list that shows their values in ... non interger form (0.8). I'm calling this function in a for loop, and this function gets repeated 20 times, pulling different info each time. This function works just fine, and does exactly what I want it to do.
def percentage(student_marks, total_quiz_marks):
def percentage(student_marks, total_quiz_marks):
quiz_precentage = []
for position in range(len(student_marks)):
quiz_precentage.append(float(student_marks[position]) / float(total_quiz_marks[position]))
return quiz_precentageHowever... I need to take the info generated by this function, and pull out the lowest mark from each of these lists that is generated. I'v tried doing that with a different function, and get nothing but errors. I've tried several different ways, and was wondering if someone would be able to help out.
•
•
Join Date: Aug 2005
Posts: 148
Reputation:
Solved Threads: 6
I'm not really sure if I understood you correctly, but maybe, this is what you want?
Python Syntax (Toggle Plain Text)
def percentage(student_marks, total_quiz_marks): quiz_precentage = [] stud_marks_min = student_marks[0]; tot_q_marks_min = total_quiz_marks[0] for position in range(len(student_marks)): quiz_precentage.append(float(student_marks[position]) / float(total_quiz_marks[position])) if stud_marks_min > student_marks[position]: stud_marks_min = student_marks[position] if tot_q_marks_min > total_quiz_marks[position]: tot_q_marks_min = total_quiz_marks[position] return ( quiz_precentage, stud_marks_min, tot_q_marks_min )
•
•
Join Date: Sep 2005
Posts: 133
Reputation:
Solved Threads: 58
Hi!
I'm also not really sure what you want, but to get the minimum of a list you can do what Micko showed, or just (a little shorter
)
Regards, mawe
I'm also not really sure what you want, but to get the minimum of a list you can do what Micko showed, or just (a little shorter
) Python Syntax (Toggle Plain Text)
minimum = min(student_marks)
Regards, mawe
•
•
Join Date: Oct 2005
Posts: 4
Reputation:
Solved Threads: 0
Maybe, but I don't think either of those will work. The lists (20) that are outputed, each contain 6 items. And I need to pull out the smallest of those marks, in each of the 20 lists that are outputed. I belive that it would have to be inside a for loop. The 2 lists that I'm taking the info from, student_marks, and total_quiz_marks, has the individual grades, and the total mark the quiz is out of (they are all different). I divide those, then I need to pull out the lowest one.
Anyway, what you gave me, gives me a new angle. Thanks.
Anyway, what you gave me, gives me a new angle. Thanks.
•
•
Join Date: Sep 2005
Posts: 133
Reputation:
Solved Threads: 58
Maybe like this?
If that's still not what you want (and I guess it is
), could you show some input and the output you expect?
Python Syntax (Toggle Plain Text)
return quiz_percentage, min(quiz_percentage)
If that's still not what you want (and I guess it is
), could you show some input and the output you expect? •
•
Join Date: Oct 2005
Posts: 4
Reputation:
Solved Threads: 0
Well it's rather messy, but it works. I just wanted to thank you micko, and mawe for helping me out. Hey, one last question.... how do you guys make your funky code thing show up like you do?
code:
def percentage(student_marks, total_quiz_marks):
code:
def percentage(student_marks, total_quiz_marks):
quiz_precentage = []
for position in range(len(student_marks)):
quiz_precentage.append(float(student_marks[position]) / float(total_quiz_marks[position]))
if min(quiz_precentage) == quiz_precentage[0]:del quiz_precentage[0]elif min(quiz_precentage) == quiz_precentage[1]:del quiz_precentage[1]elif min(quiz_precentage) == quiz_precentage[2]:del quiz_precentage[2]elif min(quiz_precentage) == quiz_precentage[3]:del quiz_precentage[3]elif min(quiz_precentage) == quiz_precentage[4]:del quiz_precentage[4]elif min(quiz_precentage) == quiz_precentage[5]:del quiz_precentage[5]return quiz_precentage
•
•
Join Date: Sep 2005
Posts: 133
Reputation:
Solved Threads: 58
•
•
•
•
Originally Posted by Riptide-X-
how do you guys make your funky code thing show up like you do?
(without the space at the first "code")•
•
•
•
[ code]the code[/code]
Python Syntax (Toggle Plain Text)
minimum = min(quiz_percentage) quiz_percentage.remove(minimum)
![]() |
Similar Threads
- VB's Left, Right, Mid Functions in C++? (C++)
- User defined functions (C++)
- Double Linked Lists and Functions required (C++)
- How to write FNVAL functions (Java)
- I dont see any difference between these 2 functions, DO YOU? (C)
- access Digital Camera Functions (C++)
Other Threads in the Python Forum
- Previous Thread: Area Unit Conversion (Python)
- Next Thread: GnomeDruid class
| Thread Tools | Search this Thread |
accessdenied advanced apache application argv array beginner book change command converter countpasswordentry csv dan08 def dictionary dynamic edit enter event examples file float format function google gui homework import inches input jaunty java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric obexftp output parameters parsing path phonebook plugin port prime programming projects py2exe pygame pygtk pyopengl pysimplewizard python random recursion redirect remote return reverse scrolledtext session simple skinning software sprite statictext string strings syntax terminal text threading time tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable voip wordgame wxpython





