-2

Sorry if this seems like a stupid question, I'm rather new to Python. I need to create a program for a school project. The project outline says this: Students can earn their final mark in a course in two ways. First the course work can be worth 60%, the final project worth 20% and the final exam worth 20%. Alternately, the course work can be worth 70%, the final project worth 10% and the final exam worth 20%. Use the following code as a start and create a program that outputs the highest grade the student could achieve.

course = 87
finalProject = 75
exam = 82

Once again, I apologize if this seems like a stupid question, I'm quite new to Python. I just need to know the best way of going about doing this.

Sumit Bijvani
  • 8,154
  • 17
  • 50
  • 82
  • 2
    What have you done so far? You can't just ask for a solution without showing some effort. – Will Custode Oct 04 '13 at 14:45
  • I've attempted to begin writing the code as best I could, but it wasn't correct, so I discarded it. Sorry if I had done something wrong or asked a question incorrectly; I'm new here. I apologize. – user2836628 Oct 04 '13 at 14:48
  • 1
    Welcome to SO. It is not enough to ask a question, you have to show us what you've done thus far. People get spammed with downvotes when they post a question saying "how do I do this entire thing". – Will Custode Oct 04 '13 at 14:50
  • Well that's not what I'm asking. I should have been more specific. I am just asking for a starting point, not the entire code. Sorry for the misunderstanding. – user2836628 Oct 04 '13 at 14:51
  • 2
    @user2836628: It's good practice on SO to accept one of the answers. – Erik Kaplun Oct 06 '13 at 17:23

4 Answers4

2

The built-in max(...) function just returns the greatest argument passed to it; it's also usable with lists: max([1, 2, 3]) => 3.

In your case:

highest = max(
    course * 0.6 + finalProject * 0.2 + exam * 0.2,
    course * 0.7 + finalProject * 0.1 + exam * 0.2
)
Erik Kaplun
  • 37,128
  • 15
  • 99
  • 111
  • 2
    Amazing... If you replace the first, second, fourth and fifth comma with a plus(+) then you literally did his project in one line. – Touch Oct 04 '13 at 15:19
  • @Touch: Oops, it was supposed to be `+` not `,`... corrected the mistake :) – Erik Kaplun Oct 04 '13 at 15:26
0

It's a simple math problem, being new to Python is irrelevant. Calculate the final mark using both equations, then check which one is larger. Output the value of the largest one.

tom
  • 2,335
  • 1
  • 16
  • 30
  • I'm aware of the fact that it is a simple math problem, one I can solve quite easily, however, I am not sure as to what code I should write. Sorry if I am frustrating you. – user2836628 Oct 04 '13 at 14:50
0

You are comparing the first and the second grading system right? Shouldn't it be just two variables? You can use max() to compare to numbers: max(a, b) returns the higher between two numbers. The rest you can solve yourself.

aIKid
  • 26,968
  • 4
  • 39
  • 65
0

It's nothing but maths. Really...

# Your starting point
course = 87
finalProject = 75
exam = 82

# What I would "crunch" into a calculator besides the variables
total1 = (course * 0.6) + (finalProject * 0.2) + (exam * 0.2)
total2 = (course * 0.7) + (finalProject * 0.1) + (exam * 0.2)

# Printing my computed answers just to make sure I can tell if it gives the right output
print "Total1: %s\tTotal2: %s" % (total1, total2)

# Printing the highest one. 
print "\nYour mark is: %s" % max(total1, total2)

See it in action: http://codepad.org/UsfAVC30

You might find this interesting: Interesting article from meta.programmers.stackexchange.com

Community
  • 1
  • 1
Touch
  • 1,481
  • 10
  • 19