Write a python function to convert a numeric input argument to a string output based on the

following rules:

>=10: A, 9:B, 8:C, 7:D, 6:E, <=5: F

I came up with this, but it does not work at all

table = {'A': 10, 'B': 9, 'C': 8, 'D': 7, 'E': 6, 'F': 5}
choice = raw_input("Please enter a number: ")
for letter, number in table.items():
    if number >= 10:
        print letter

    if number == 9:
        print letter

    if number == 8:
        print letter

    if number == 7:
        print letter

    if number == 6:
        print letter

    if number == 5:
        print letter

Recommended Answers

All 4 Replies

This should solve the problem, below is the correct way to search a dictionary with a for loop.

def solve():
    dict = {9:'B', 8:'C', 7:'D', 6:'E'}
    choice = raw_input("Please enter a number: ")

    if int(choice) >= 10:
        return 'A'
    elif int(choice) <= 5:
        return 'F'
    else:
        for letter in dict:
            if int(choice) == letter:
                return dict[letter]

def main():
    print solve()
    
if __name__ == '__main__':
    main()

Wow, I can't barely wait till
Python Coding Help Pt 3
cames around!

^^we got a jokester haha, dude why even waist your time if your not contributing to the thread

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.