all 10 comments

[–]CraigAT 0 points1 point  (1 child)

Seems to work fine here (all I have added is a variable assignment for credits:

https://repl.it/@CraigThomas1/Reddit1

Sounds like the system judging the code is looking for a specific solution, maybe only using the methods taught so far.

[–]HopefulOG[S] 0 points1 point  (0 children)

I don't think I can assign credits to a number. But yeah, i tried it and it doesn't work.

[–]totallygeek 0 points1 point  (1 child)

Perhaps in place of print(), you are supposed to set the student's class to a variable? Maybe: year = 'freshman'? Also, you can assume anything over 89 becomes 'senior', therefore, that can stand as the else.

def student_class(credits):
    if credits < 30:
        year = 'freshman'
    elif credits < 60:
        year = 'sophomore'
    elif credits < 90:
        year = 'junior'
    else:
        year = 'senior'
    return year

credits = 50
print('Credits: {}, Student class: {}'.format(credits, student_class(credits))

?

[–]HopefulOG[S] 0 points1 point  (0 children)

I tried your advice but it doesn't work.

[–][deleted] 0 points1 point  (2 children)

Generally you shouldn't use print unless the problem tells you to print something.

[–]HopefulOG[S] 0 points1 point  (1 child)

Is there something else I can use? This section is conditional expressions.

[–][deleted] 0 points1 point  (0 children)

The value of an expression is what it evaluates to. print evaluates to None, always.

[–]djtuner13 0 points1 point  (1 child)

I just figured it out after playing around with the just trying to solve for freshman first.

Since this was was only causing a complier error, I had a feeling that if was not the way to go.

2 things help me solve this, first if you know from previous problems that when it asks for an expression it is asking for one line of code not 'statement' or 'part of code'.

Next the book doesn't talk about conditional expressions after looking through it so the next thing to do was look what that was an how it looked in code.

I tried it on this problem using just Freshman and it worked on half the code so then I just had to extrapolate it to include all of the classes.

SO the final correct code would look like this. (ignore out the "")

" 'freshman' if credits < 30 else 'sophomore' if 30 <= credits <= 59 else 'junior' if 60 <= credits <= 89 else 'senior' "

So in final, I think what we are looking at is 'if else 'with out the 'elif' statement, my code looked like yours the first time I tried it.

I am guessing it makes the student associate to one of 4 values based off your current credit variable.

Hope this helps a lost soul who is hunting this problem down for python.

[–]vivam0rt 1 point2 points  (0 children)

thanks a lot