10 Replies - 1144 Views - Last Post: 18 August 2012 - 09:21 AM Rate Topic: -----

#1 mike316  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 04-July 12

question about my if,elif,else statements.

Posted 17 August 2012 - 07:46 PM

I was wondering if someone could help me out and point me in the right direction here. First you enter 5 test scores using a for loop, it will then calculate the average of the five scores. I would like to calculate the grade for each test score entered by the user. For example if you enter 80% for the first it print"your grade is B', then if you enter 90% it would print 'Your grade is A. Instead my program takes the average and prints the grade. Thanks in advance for the help.
# 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()


Is This A Good Question/Topic? 0
  • +

Replies To: question about my if,elif,else statements.

#2 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: question about my if,elif,else statements.

Posted 17 August 2012 - 08:01 PM

It feels like someone else wrote this program for you and your homework assignment is to edit it accordingly. I don't ask other people to do my homework and neither should you. Show some effort and we can help.
Was This Post Helpful? 0
  • +
  • -

#3 mike316  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 04-July 12

Re: question about my if,elif,else statements.

Posted 17 August 2012 - 08:17 PM

View Postatraub, on 17 August 2012 - 08:01 PM, said:

It feels like someone else wrote this program for you and your homework assignment is to edit it accordingly. I don't ask other people to do my homework and neither should you. Show some effort and we can help.


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.
Was This Post Helpful? 0
  • +
  • -

#4 GunnerInc  Icon User is online

  • "Hurry up and wait"
  • member icon




Reputation: 866
  • View blog
  • Posts: 2,309
  • Joined: 28-March 11

Re: question about my if,elif,else statements.

Posted 17 August 2012 - 08:24 PM

So what does the book say? Or are you trying to skip ahead?
Was This Post Helpful? 0
  • +
  • -

#5 mike316  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 04-July 12

Re: question about my if,elif,else statements.

Posted 17 August 2012 - 08:31 PM

I'll ask the moderator to close/delete this thread, and delete my account. I'll figure it out on my own. I'm rather embarresed to be accused of this being homework. I'm just a newb that needs a little helping, I can try to elsewhere also.
Was This Post Helpful? 0
  • +
  • -

#6 alexr1090  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 44
  • View blog
  • Posts: 125
  • Joined: 08-May 11

Re: question about my if,elif,else statements.

Posted 17 August 2012 - 09:41 PM

View Postmike316, on 17 August 2012 - 10:31 PM, said:

I'll ask the moderator to close/delete this thread, and delete my account. I'll figure it out on my own. I'm rather embarresed to be accused of this being homework. I'm just a newb that needs a little helping, I can try to elsewhere also.


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).
Was This Post Helpful? 1
  • +
  • -

#7 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: question about my if,elif,else statements.

Posted 17 August 2012 - 10:10 PM

View Postalexr1090, on 18 August 2012 - 12:41 AM, said:

View Postmike316, on 17 August 2012 - 10:31 PM, said:

I'll ask the moderator to close/delete this thread, and delete my account. I'll figure it out on my own. I'm rather embarresed to be accused of this being homework. I'm just a newb that needs a little helping, I can try to elsewhere also.


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

Was This Post Helpful? 0
  • +
  • -

#8 mike316  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 04-July 12

Re: question about my if,elif,else statements.

Posted 17 August 2012 - 10:14 PM

View Postalexr1090, on 17 August 2012 - 09:41 PM, said:

View Postmike316, on 17 August 2012 - 10:31 PM, said:

I'll ask the moderator to close/delete this thread, and delete my account. I'll figure it out on my own. I'm rather embarresed to be accused of this being homework. I'm just a newb that needs a little helping, I can try to elsewhere also.


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.

View Postatraub, on 17 August 2012 - 10:10 PM, said:

View Postalexr1090, on 18 August 2012 - 12:41 AM, said:

View Postmike316, on 17 August 2012 - 10:31 PM, said:

I'll ask the moderator to close/delete this thread, and delete my account. I'll figure it out on my own. I'm rather embarresed to be accused of this being homework. I'm just a newb that needs a little helping, I can try to elsewhere also.


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.
Was This Post Helpful? 0
  • +
  • -

#9 alexr1090  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 44
  • View blog
  • Posts: 125
  • Joined: 08-May 11

Re: question about my if,elif,else statements.

Posted 17 August 2012 - 10:51 PM

View Postatraub, on 18 August 2012 - 12:10 AM, said:

View Postalexr1090, on 18 August 2012 - 12:41 AM, said:

View Postmike316, on 17 August 2012 - 10:31 PM, said:

I'll ask the moderator to close/delete this thread, and delete my account. I'll figure it out on my own. I'm rather embarresed to be accused of this being homework. I'm just a newb that needs a little helping, I can try to elsewhere also.


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 :oops: . I do admire you though man. When I said you're a really smart and helpful person I meant it. Have a good one bro.
Was This Post Helpful? 0
  • +
  • -

#10 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5932
  • View blog
  • Posts: 12,855
  • Joined: 16-October 07

Re: question about my if,elif,else statements.

Posted 18 August 2012 - 05:03 AM

I, um, +1 alexr1090. This isn't a dis to those who choose to call people out. Though, personally, I usually save the call out for my second post. Rather, I feel it's always better to be helpful than adversarial.

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)


Was This Post Helpful? 0
  • +
  • -

#11 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: question about my if,elif,else statements.

Posted 18 August 2012 - 09:21 AM

Upon reviewing my post after a good night's sleep... I was too harsh. Looking at alexr1090's post history... well it seems I got some wires crossed and fused alexr1090 with another guy who has been chronically rewriting people's programs rather than giving them the opportunity to solve the issues themselves. I apologize for that.

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1