0

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

Edited by pritaeas: Fixed formatting

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by the_mia_team
Featured Replies
  • This should solve the problem, below is the correct way to search a dictionary with a for loop. [CODE]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: … Read More

2

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()
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.