Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
April 16th, 2013, 03:45 PM
 newtothis1
Registered User

Join Date: Apr 2013
Posts: 6
Time spent in forums: 3 h 24 m 35 sec
Reputation Power: 0

I am stuck on this assignment and it is driving me nuts.

You will write a program that will use two functions:

computeMetric - this function will compute a metric based on grades from specific classes. This function will take four parameters (the four class scores) and will return a single floating point metric value. The multiplier for each class is also shown. Multiply each class grade by its factor, then return the sum of the classes.
ENG101 (.5)
ENG210 (1.5)
CMST210 (.75)
CMST340 (1.25)

printStudent - this function will take 5 parameters and print the name, class scores and computed metric. It will compute the metric by calling the computeMetric function. This function should print with tabs between each element. (i.e. Brian Kamp 4.0 3.0 3.5 2.0 Metric:11.625) The five parameters are:
name (str)
ENG101 (float)
ENG210 (float)
CMST210 (float)
CMST340 (float)

Your main program should ask the user input for name, English 101 score, English 210 score, Comm Studies 210 and Comm Studies 340. It will then print out the information by calling the printStudent function (above).

I have this so far....

def computeMetric(ENG101, ENG210, CMST210, CMST340):
metric = ENG101 * .5 + ENG210 * 1.5 + CMST340 * .75 + CMST340 * 1.25

#2
April 16th, 2013, 04:42 PM
Registered User

Join Date: Apr 2013
Posts: 4
Time spent in forums: 1 h 37 m 39 sec
Reputation Power: 0
Do you still need help?
This is a fairly simple program, all you need is your basic arithmetic

#3
April 16th, 2013, 04:49 PM
 newtothis1
Registered User

Join Date: Apr 2013
Posts: 6
Time spent in forums: 3 h 24 m 35 sec
Reputation Power: 0
Quote:
 Originally Posted by mrkonrad Do you still need help? This is a fairly simple program, all you need is your basic arithmetic

yes i do still need help.

This is what I have so far...

def computeMetric(ENG101, ENG210, CMST210, CMST340):
metric = ENG101 * .5 + ENG210 * 1.5 + CMST340 * .75 + CMST340 * 1.25

name = str(input("Enter Student's Name:"))
ENG101 = float(input("Enter English 101 Score:"))
ENG210 = float(input("Enter English 210 Score:"))
CMST210 = float(input("Enter Comm Studies 210 Score:"))
CMST340 = float(input("Enter Comm Studies 340 Score:"))

print(name, ENG101, ENG210, CMST210, CMST340)

I am just trying to get the computed Metric back after i enter the name and grades

#4
April 16th, 2013, 05:47 PM
Registered User

Join Date: Apr 2013
Posts: 4
Time spent in forums: 1 h 37 m 39 sec
Reputation Power: 0
Quote:
 Originally Posted by newtothis1 I am just trying to get the computed Metric back after i enter the name and grades

Do you want the user to enter it himself like: computeMetric(78, 90, 45, 21) or do you want to present him the metric just from the input

#5
April 16th, 2013, 05:49 PM
 newtothis1
Registered User

Join Date: Apr 2013
Posts: 6
Time spent in forums: 3 h 24 m 35 sec
Reputation Power: 0
Quote:
 Originally Posted by mrkonrad Do you want the user to enter it himself like: computeMetric(78, 90, 45, 21) or do you want to present him the metric just from the input

just from inputting the 4 class scores when asked to type them in

#6
April 16th, 2013, 06:01 PM
Registered User

Join Date: Apr 2013
Posts: 4
Time spent in forums: 1 h 37 m 39 sec
Reputation Power: 0
Quote:
 Originally Posted by newtothis1 just from inputting the 4 class scores when asked to type them in

name = raw_input("Enter Student's Name:")
ENG101 = float(input("Enter English 101 Score:"))
ENG210 = float(input("Enter English 210 Score:"))
CMST210 = float(input("Enter Comm Studies 210 Score:"))
CMST340 = float(input("Enter Comm Studies 340 Score:"))
metric = ENG101 * .5 + ENG210 * 1.5 + CMST340 * .75 + CMST340 * 1.25
print(name, ENG101, ENG210, CMST210, CMST340)
print "Metric = " + str(metric)

that seems to work, do you need it in a function?

EDIT: heres the function if you want it
Code:
```def Grading():
name = raw_input("Enter Student's Name:")
ENG101 = float(input("Enter English 101 Score:"))
ENG210 = float(input("Enter English 210 Score:"))
CMST210 = float(input("Enter Comm Studies 210 Score:"))
CMST340 = float(input("Enter Comm Studies 340 Score:"))
metric = ENG101 * .5 + ENG210 * 1.5 + CMST340 * .75 + CMST340 * 1.25
return str((name, ENG101, ENG210, CMST210, CMST340)) + "\n"+ "Metric = " + str(metric)

#7
April 16th, 2013, 06:06 PM
 newtothis1
Registered User

Join Date: Apr 2013
Posts: 6
Time spent in forums: 3 h 24 m 35 sec
Reputation Power: 0
Quote:
 Originally Posted by mrkonrad name = raw_input("Enter Student's Name:") ENG101 = float(input("Enter English 101 Score:")) ENG210 = float(input("Enter English 210 Score:")) CMST210 = float(input("Enter Comm Studies 210 Score:")) CMST340 = float(input("Enter Comm Studies 340 Score:")) metric = ENG101 * .5 + ENG210 * 1.5 + CMST340 * .75 + CMST340 * 1.25 print(name, ENG101, ENG210, CMST210, CMST340) print "Metric = " + str(metric) that seems to work, do you need it in a function?

I have tried what you have written and it gives me invalid syntax error after "Metric = "

#8
April 16th, 2013, 06:12 PM
Registered User

Join Date: Apr 2013
Posts: 4
Time spent in forums: 1 h 37 m 39 sec
Reputation Power: 0
Quote:
 Originally Posted by newtothis1 I have tried what you have written and it gives me invalid syntax error after "Metric = "

its working perfectly for me..
which version are you using, not exactly an expert but that might be it.
and try this
Code:
```def Grading():
name = raw_input("Enter Student's Name:")
ENG101 = float(input("Enter English 101 Score:"))
ENG210 = float(input("Enter English 210 Score:"))
CMST210 = float(input("Enter Comm Studies 210 Score:"))
CMST340 = float(input("Enter Comm Studies 340 Score:"))
metric = ENG101 * .5 + ENG210 * 1.5 + CMST340 * .75 + CMST340 * 1.25
return str((name, ENG101, ENG210, CMST210, CMST340)) + "\n"+ "Metric = " + str(metric)

#9
April 16th, 2013, 06:14 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,124
Time spent in forums: 1 Month 3 Weeks 2 Days 4 h 37 m 27 sec
Reputation Power: 455
Yes, one of you uses python2 and newtothis1 uses python3.
__________________
[code]Code tags[/code] are essential for python code!

#10
April 16th, 2013, 06:16 PM
 newtothis1
Registered User

Join Date: Apr 2013
Posts: 6
Time spent in forums: 3 h 24 m 35 sec
Reputation Power: 0
Quote:
 Originally Posted by mrkonrad its working perfectly for me.. which version are you using, not exactly an expert but that might be it. and try this Code: ```def Grading(): name = raw_input("Enter Student's Name:") ENG101 = float(input("Enter English 101 Score:")) ENG210 = float(input("Enter English 210 Score:")) CMST210 = float(input("Enter Comm Studies 210 Score:")) CMST340 = float(input("Enter Comm Studies 340 Score:")) metric = ENG101 * .5 + ENG210 * 1.5 + CMST340 * .75 + CMST340 * 1.25 return str((name, ENG101, ENG210, CMST210, CMST340)) + "\n"+ "Metric = " + str(metric) print Grading()```

i am using python 3.3 and i just tried this and it says invalid syntax and highlights Grading in red on the bottom

#11
April 16th, 2013, 06:21 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,124
Time spent in forums: 1 Month 3 Weeks 2 Days 4 h 37 m 27 sec
Reputation Power: 455
You've been given so much help please take it upon yourself to rewrite
metric = ENG101 * .5 + ENG210 * 1.5 + CMST340 * .75 + CMST340 * 1.25
as a dot product.

metric = dot(weights, grades) # something like this

#12
April 16th, 2013, 06:30 PM
 newtothis1
Registered User

Join Date: Apr 2013
Posts: 6
Time spent in forums: 3 h 24 m 35 sec
Reputation Power: 0
Quote:
 Originally Posted by b49P23TIvg You've been given so much help please take it upon yourself to rewrite metric = ENG101 * .5 + ENG210 * 1.5 + CMST340 * .75 + CMST340 * 1.25 as a dot product. metric = dot(weights, grades) # something like this

I honestly have no idea what is going on. This is my first program and my teacher expects this done tonight. I am going off of what I have learned in class in 2 days. This is all I have so far.

def computeMetric(ENG101, ENG210, CMST210, CMST340):
metric = ENG101 * .5 + ENG210 * 1.5 + CMST340 * .75 + CMST340 * 1.25

print(metric)

name = str(input("Enter Student's Name:"))
ENG101 = float(input("Enter English 101 Score:"))
ENG210 = float(input("Enter English 210 Score:"))
CMST210 = float(input("Enter Comm Studies 210 Score:"))
CMST340 = float(input("Enter Comm Studies 340 Score:"))

def printStudent(

I do not know what to do now. When i run the module it asks me for the data so i input random values. After i input the values i want to be able to type in the function printStudent and would like for it to show me the name, each class score, and the metric.

Help would be appreciated.

#13
April 16th, 2013, 07:30 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,124
Time spent in forums: 1 Month 3 Weeks 2 Days 4 h 37 m 27 sec
Reputation Power: 455
Code:
```def computeMetric(ENG101:float, ENG210:float, CMST210:float, CMST340:float)->float:
metric = ENG101 * .5 + ENG210 * 1.5 + CMST340 * .75 + CMST340 * 1.25 # can you spot the error in this line?
#metric = sum(w*g for (w,g,) in zip((0.5,1.5,0.75,1.25,),(ENG101, ENG210, CMST210, CMST340))) # computed as a dot product
return metric ################ return the value, don't print it.

def printStudent(name:str, ENG101:float, ENG210:float, CMST210:float, CMST340:float)->None:
'''
>>> printStudent('Brian Kamp',4,3,3.5,2)
Brian Kamp\t4.0\t3.0\t3.5\t2.0\tMetric:11.625
'''
metric = computeMetric(ENG101, ENG210, CMST210, CMST340)
print(('{}'+'\t{:.1f}'*4+'\tMetric:{}').format(name, ENG101, ENG210, CMST210, CMST340, metric))

name = str(input("Enter Student's Name:"))
ENG101 = float(input("Enter English 101 Score:"))
ENG210 = float(input("Enter English 210 Score:"))
CMST210 = float(input("Enter Comm Studies 210 Score:"))
CMST340 = float(input("Enter Comm Studies 340 Score:"))```

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > Can someone please help me make a program for class