Advertisement
FedeCuci

Untitled

Apr 3rd, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import time
  2.  
  3. # Create dictionary containing all letters in the alphabet
  4. alphabet = {
  5. 'a' : 1,
  6. 'b' : 2,
  7. 'c' : 3,
  8. 'd' : 4,
  9. 'e' : 5,
  10. 'f' : 6,
  11. 'g' : 7,
  12. 'h' : 8,
  13. 'i' : 9,
  14. 'j' : 10,
  15. 'k' : 11,
  16. 'l' : 12,
  17. 'm' : 13,
  18. 'n' : 14,
  19. 'o' : 15,
  20. 'p' : 16,
  21. 'q' : 17,
  22. 'r' : 18,
  23. 's' : 19,
  24. 't' : 20,
  25. 'u' : 21,
  26. 'v' : 22,
  27. 'w' : 23,
  28. 'x' : 24,
  29. 'y' : 25,
  30. 'z' : 26
  31.  
  32. }
  33.  
  34. letter = input('Letter: ').lower() # Ask input
  35.  
  36. start = time.time()
  37.  
  38. if letter in alphabet.keys(): # Check if input is in our dictionary keys (letters)
  39. print('{} is the {} term in the alphabet'.format(letter, alphabet[letter])) # Return letter, and value of given letterin the dictionary
  40. end = time.time()
  41. print(float(end-start))
  42. else:
  43. print('Please enter a valid letter')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement