0

The promoter wants to be able to classify donors based on how much they have contributed to the overall goal of the campaign.

Write a function easy_donor_rank(percent_donated) that takes a number indicating percent donated and returns a string containing the rank attained by giving such a donation.

For example, the function call easy_donor_rank(1.0) should return the string 'Bronze'.

See the table below to see the list of donor ranks.

Donor Classification

  • Donation Percentage Donor Rank
  • 0% or less
  • Error Less than 2% Bronze
  • 2% to 15% inclusive Silver more than 15% Gold

The code I have right now works but I always get a "None" in the end of every output

def easy_donor_rank(percent_donated):

    if percent_donated <= 0:
        print("Error")

    if percent_donated < 2:
        print("Bronze")

    elif percent_donated >= 2 and percent_donated <= 15:
        print("Silver")

    else:
        print("Gold")
Til
  • 5,150
  • 13
  • 26
  • 34
  • "_I always get a "None" in the end of every output_" : I think it's because you just `print` the result instead of actually `return`ing it, as stated in the instructions. – Gino Mempin Mar 19 '19 at 04:18

3 Answers3

0

Basically, your code works for me. I made a small modification only for your if condition. I change the second if to elif.

def easy_donor_rank(percent_donated):
    if percent_donated <= 0:
        print("Error")
    elif percent_donated < 2:
        print("Bronze")
    elif percent_donated <= 15:
        print("Silver")
    else:
        print("Gold")
YusufUMS
  • 1,506
  • 1
  • 12
  • 24
0

it's work in python 3.6

def easy_donor_rank(percent_donated):
    if percent_donated <= 0:
        return "Error"
    elif percent_donated < 2:
        return ("Bronze")

    elif percent_donated >= 2 and percent_donated <= 15:
        return ("Silver")
    else:
        return ("Gold")
soheshdoshi
  • 594
  • 3
  • 7
  • 24
0

The code I have right now works but I always get a "None" in the end of every output.

I'm going to assume that you are trying to print the return of easy_donor_rank.

$ cat test.py
def easy_donor_rank(percent_donated):    
    if percent_donated <= 0:
        print("Error")
    if percent_donated < 2:
        print("Bronze")
    elif percent_donated >= 2 and percent_donated <= 15:
        print("Silver")
    else:
        print("Gold")

print(easy_donor_rank(1.2))

But because you don't return anything, it will return None, so None gets printed.

$ python3 test.py
Bronze
None

You just need to return the result instead of printing it inside the function.
See What is the purpose of the return statement?

$ cat test.py
def easy_donor_rank(percent_donated):
    if percent_donated <= 0:
        return "Error"
    if percent_donated < 2:
        return "Bronze"
    elif percent_donated >= 2 and percent_donated <= 15:
        return ("Silver")
    else:
        return "Gold"

print(easy_donor_rank(1.2))

$ python3 test.py
Bronze
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135