help with functions

Reply

Join Date: Oct 2005
Posts: 4
Reputation: Riptide-X- is an unknown quantity at this point 
Solved Threads: 0
Riptide-X- Riptide-X- is offline Offline
Newbie Poster

help with functions

 
0
  #1
Nov 6th, 2005
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):
quiz_precentage = []
for position in range(len(student_marks)):
quiz_precentage.append(float(student_marks[position]) / float(total_quiz_marks[position]))
return quiz_precentage
However... 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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 148
Reputation: Micko is on a distinguished road 
Solved Threads: 6
Micko Micko is offline Offline
Junior Poster

Re: help with functions

 
0
  #2
Nov 6th, 2005
I'm not really sure if I understood you correctly, but maybe, this is what you want?

  1. def percentage(student_marks, total_quiz_marks):
  2.  
  3. quiz_precentage = []
  4. stud_marks_min = student_marks[0];
  5. tot_q_marks_min = total_quiz_marks[0]
  6.  
  7. for position in range(len(student_marks)):
  8.  
  9. quiz_precentage.append(float(student_marks[position]) / float(total_quiz_marks[position]))
  10.  
  11. if stud_marks_min > student_marks[position]:
  12. stud_marks_min = student_marks[position]
  13. if tot_q_marks_min > total_quiz_marks[position]:
  14. tot_q_marks_min = total_quiz_marks[position]
  15.  
  16. return ( quiz_precentage, stud_marks_min, tot_q_marks_min )
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 133
Reputation: mawe is an unknown quantity at this point 
Solved Threads: 58
mawe mawe is offline Offline
Junior Poster

Re: help with functions

 
0
  #3
Nov 6th, 2005
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 )
  1. minimum = min(student_marks)

Regards, mawe
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 4
Reputation: Riptide-X- is an unknown quantity at this point 
Solved Threads: 0
Riptide-X- Riptide-X- is offline Offline
Newbie Poster

Re: help with functions

 
0
  #4
Nov 6th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 133
Reputation: mawe is an unknown quantity at this point 
Solved Threads: 58
mawe mawe is offline Offline
Junior Poster

Re: help with functions

 
0
  #5
Nov 6th, 2005
Maybe like this?
  1. 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?
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 4
Reputation: Riptide-X- is an unknown quantity at this point 
Solved Threads: 0
Riptide-X- Riptide-X- is offline Offline
Newbie Poster

Re: help with functions

 
0
  #6
Nov 6th, 2005
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):
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 133
Reputation: mawe is an unknown quantity at this point 
Solved Threads: 58
mawe mawe is offline Offline
Junior Poster

Re: help with functions

 
0
  #7
Nov 6th, 2005
Originally Posted by Riptide-X-
how do you guys make your funky code thing show up like you do?
Just put your code in code-tags (without the space at the first "code")
[ code]the code[/code]
Instead of your many if's, you could write
  1. minimum = min(quiz_percentage)
  2. quiz_percentage.remove(minimum)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC