how could i call the above function so that when i input something like 21 for the mark the ouput is "the grade is A", and when the user inputs something more than 25 and less than 0 hes asked to input it again..?

if mark >=20:
return "A"
elif mark >=15:
return "B"
elif mark >=10:
return "C"
else:
return "Fail"

2
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by gangster88

you almost have it, all you have to do is to call the function with mark as an argument like this:

if m >= 20:
return "A"
elif m >= 15:
return "B"
elif m >= 10:
return "C"
else:
return "Fail"

mark = input( "Please enter the mark: " )

See if you can figure out how to implement the check for validity, i.e. < 0 and > 25 :)

Edited by masterofpuppets: n/a

you almost have it, all you have to do is to call the function with mark as an argument like this:

if m >= 20:
return "A"
elif m >= 15:
return "B"
elif m >= 10:
return "C"
else:
return "Fail"

mark = input( "Please enter the mark: " )

See if you can figure out how to implement the check for validity, i.e. < 0 and > 25 :)

anything on these lines?

mark = input( "Please enter the mark: " )
if mark >25:
else:
print"try again"

hi,

mark = input( "Please enter the mark: " )
if mark >25:
else:
print"try again"

be careful with the indentation for the else statement here :)

Now, this means that the result will be shown only if the mark is greater than 25, which is not helpful. You need the mark to be in range 0 <= mark <= 25 right? so the if would be:

mark = input( "Please enter the mark: " )
if 0 > mark or mark > 25:
print "Try again!"
else:

Edited by masterofpuppets: n/a

hi,

be careful with the indentation for the else statement here :)

Now, this means that the result will be shown only if the mark is greater than 25, which is not helpful. You need the mark to be in range 0 <= mark <= 25 right? so the if would be: