Python Development bisect

Source: Internet
Author: User
Now there are the following requirements:

"    to achieve such a function:    a class of students to make some assessment, the rules are: one    : [0-60)     --F-double    : [60-70)-    -D    Three: [ 70-80)  --C four    : [80-90   ]--B    five: [90-100]  --A ' "

The bisect in Python can achieve the above requirements

Operating effect:

#python bisect "To achieve such a function: to a class of students to make some assessment, the rules are: one: [0-60)--F: [60-70)--D Three: [70- ---C four: [80-90]--B five: [90-100]--a ######################################### you'll probably think of using: if ....    else ... Or think of using: Switch ... (Java) ########################################## the following two methods are not used to achieve this function "' Import randomimport bisectdef Create_studen T_scores (n): #根据学生人数n, create student score if n >= 0:scores = [] for x in range (n): Scores.append (ran    Dom.randrange (0, 101, 1)) Return scores else:print (' The number should be greater than 0! ') def grade (score, breakpoints = [Max, Max, Max], grades = ' FDCBA '): i = Bisect.bisect (breakpoints, score) return GRA Des[i]def Main (): Student_scores = Create_student_scores (Ten) student_results = [Grade (score) for score in STUDENT_SC Ores] Print (' Student score: {}\n rating result: {} '. Format (student_scores, student_results)) if __name__ = = ' __main__ ': Main ()
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.