# Declaring the variables
def main():
total = 0.0
for counter in range(5):
test = input('Enter five test scores ')
total = total + test
calc_average=average(total)
determine_grade(test)
printInfo(calc_average)
# calling the functions
def average(total):
calc_average=total/5
calc_average=float(calc_average)
return calc_average
# my if,elif, else, statements below I
# thinks this is were my problem is.
def determine_grade(test):
if test < 60:
print'Your grade is F'
elif test < 70:
print 'Your grade is D'
elif test < 80:
print 'Your grade is C'
elif test < 90:
print 'Your grade is B'
else:
print 'Your grade is A'
return test
# displays the info.
def printInfo(calc_average):
print 'The average for test scores is: ',calc_average
main()
question about my if,elif,else statements.
Page 1 of 110 Replies - 682 Views - Last Post: 18 August 2012 - 09:21 AM
#1
question about my if,elif,else statements.
Posted 17 August 2012 - 07:46 PM
Replies To: question about my if,elif,else statements.
#2
Re: question about my if,elif,else statements.
Posted 17 August 2012 - 08:01 PM
#3
Re: question about my if,elif,else statements.
Posted 17 August 2012 - 08:17 PM
atraub, on 17 August 2012 - 08:01 PM, said:
No this isn't homework, this is for my own enjoyment. I'm just trying to learn something new. I picked a book from a garage sale this past summer, and that's the truth.
#4
Re: question about my if,elif,else statements.
Posted 17 August 2012 - 08:24 PM
#5
Re: question about my if,elif,else statements.
Posted 17 August 2012 - 08:31 PM
#6
Re: question about my if,elif,else statements.
Posted 17 August 2012 - 09:41 PM
mike316, on 17 August 2012 - 10:31 PM, said:
I hear you dude. Basically you want to call the function that prints the grade right after you get the grade. When the code is written like this
for counter in range(5):
test = input('Enter five test scores ')
total = total + test
, you see every time your loop iterates it's going to write over what was in test. So before it goes to the next iteration you want to call the function that prints based on what was entered (before it's written over with a new value).
#7
Re: question about my if,elif,else statements.
Posted 17 August 2012 - 10:10 PM
alexr1090, on 18 August 2012 - 12:41 AM, said:
mike316, on 17 August 2012 - 10:31 PM, said:
I hear you dude. Basically you want to call the function that prints the grade right after you get the grade. When the code is written like this
for counter in range(5):
test = input('Enter five test scores ')
total = total + test
, you see every time your loop iterates it's going to write over what was in test. So before it goes to the next iteration you want to call the function that prints based on what was entered (before it's written over with a new value).
Are you naive, stupid, or simply have no respect for GunnerInc and me? Look at the facts, the poster somehow has functions already written to do exactly what he needs. How convenient! On top of that, his code is actually well written (Ie, documented and modular), sure he uses input over raw_input in a clearly py2 application, but that's par for the course.
So everything's laid out in front of him and he's using good programming practices... but somehow he doesn't understand why his function isn't working when he doesn't fucking call it? But of course, he obviously wrote all this code from scratch and Gunner and I are the local trolls for probing a little. Thank goodness for members like you alexr1090.
This post has been edited by atraub: 17 August 2012 - 10:16 PM
#8
Re: question about my if,elif,else statements.
Posted 17 August 2012 - 10:14 PM
alexr1090, on 17 August 2012 - 09:41 PM, said:
mike316, on 17 August 2012 - 10:31 PM, said:
I hear you dude. Basically you want to call the function that prints the grade right after you get the grade. When the code is written like this
for counter in range(5):
test = input('Enter five test scores ')
total = total + test
, you see every time your loop iterates it's going to write over what was in test. So before it goes to the next iteration you want to call the function that prints based on what was entered (before it's written over with a new value).
Thank you for the help. I'm sorry to see you got a -1 on your "was this post helpful" The admin. said he won't delete my post and to not log in anymore, my account will become inactive, which I will do. It seems I've annoyed some people here.Maybe I'll see you around some place else, I just wanted to say thanks. Also I'll give you a + for "Was this post helpful.
atraub, on 17 August 2012 - 10:10 PM, said:
alexr1090, on 18 August 2012 - 12:41 AM, said:
mike316, on 17 August 2012 - 10:31 PM, said:
I hear you dude. Basically you want to call the function that prints the grade right after you get the grade. When the code is written like this
for counter in range(5):
test = input('Enter five test scores ')
total = total + test
, you see every time your loop iterates it's going to write over what was in test. So before it goes to the next iteration you want to call the function that prints based on what was entered (before it's written over with a new value).
Man you're either naive or stupid. Look at the facts, the poster somehow has functions already written to do exactly what he needs. How convenient! On top of that, his code is actually well written (Ie, documented and modular), sure he uses input over raw_input in a clearly py2 application, but that's par for the course.
So everything's laid out in front of him and he's using good programming practices... but somehow he doesn't understand why his function isn't working when he doesn't fucking call it? But of course, he obviously wrote all this code from scratch and I'm just the local troll for probing a little.
Sorry dude, The only thing I'm good at is using for loops, I figured in the book it was easier to use for loops because it asks for 5 test inputs. Man alive, I was just stuck on little part, sorry if my brain got stuck. Thanks for making me feel stupid and not welcome here. I know I'm not the best programmer in the world....just a newb.
#9
Re: question about my if,elif,else statements.
Posted 17 August 2012 - 10:51 PM
atraub, on 18 August 2012 - 12:10 AM, said:
alexr1090, on 18 August 2012 - 12:41 AM, said:
mike316, on 17 August 2012 - 10:31 PM, said:
I hear you dude. Basically you want to call the function that prints the grade right after you get the grade. When the code is written like this
for counter in range(5):
test = input('Enter five test scores ')
total = total + test
, you see every time your loop iterates it's going to write over what was in test. So before it goes to the next iteration you want to call the function that prints based on what was entered (before it's written over with a new value).
Are you naive, stupid, or simply have no respect for GunnerInc and me? Look at the facts, the poster somehow has functions already written to do exactly what he needs. How convenient! On top of that, his code is actually well written (Ie, documented and modular), sure he uses input over raw_input in a clearly py2 application, but that's par for the course.
So everything's laid out in front of him and he's using good programming practices... but somehow he doesn't understand why his function isn't working when he doesn't fucking call it? But of course, he obviously wrote all this code from scratch and Gunner and I are the local trolls for probing a little. Thank goodness for members like you alexr1090.
I think you're a really smart and helpful person on here. I didn't mean to upset you man, sorry about that
#10
Re: question about my if,elif,else statements.
Posted 18 August 2012 - 05:03 AM
Giving someone crap who's clearly just trying to be helpful, and doing so in apropriate way, is a far greater faux pas than helping in spite of others telling the OP to fuck off.
Here's my help to the OP. Feel free to abuse me as you see fit.
# since you only use total in main, do it here
# and, hell, make it modular
def getTotal(scoreCount):
total = 0.0
# ask the question here:
print 'Enter', scoreCount, 'test scores '
for counter in range(scoreCount):
score = input('Enter score:')
total = total + score
return total
def main():
scoreCount = 5
total = getTotal(scoreCount)
# now it's clear you're passing test
# what the hell is test
determine_grade(test)
# why not
printInfo(total, scoreCount)
#11
Re: question about my if,elif,else statements.
Posted 18 August 2012 - 09:21 AM
However, I will say, no one instructed the OP to "fuck off." The post did look like it was a "do my hw" post but not quite so blatantly obvious to fall under Gimmeh Teh Codez. I asked him to "show some effort", and perhaps I could have been more specific as to what that would entail.
|
|

New Topic/Question
Reply



MultiQuote








|