As title say this will be a sticky thread where we all can post small to medium Scripts/Snippets.
Index over scripts in this thread.
Small to medium Scripts/Snippets
|
As title say this will be a sticky thread where we all can post small to medium Scripts/Snippets.
Index over scripts in this thread.
Sep-20-2016, 01:32 PM
Old convert grades problem without if,elif.., using Bisect.
import bisect def grade(total): return grades[bisect.bisect(breakpoints, total)] if __name__ == '__main__': # F is 30 or lower,45-60 is E ect... grades = "FEDCBA" breakpoints = [30, 45, 60, 75, 85] # Students heroes = dict(Superman=90, Hulk=25, Batman=50) for k,v in heroes.items(): print('{} had score of: {} which is grad: {}'.format(k, v, grade(v))) '''Output--> Hulk had score of: 25 which is grad: F Batman had score of: 50 which is grad: D Superman had score of: 90 which is grad: A ''' |
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
300 free curated Python code snippets | steve_shambles | 1 | 63,066 |
Jul-14-2020, 03:32 PM Last Post: HarleyQuin |
|
200 Python code snippets free | steve_shambles | 6 | 5,146 |
Apr-19-2020, 12:38 PM Last Post: Calli |