"Python exercises" string fragment

Source: Internet
Author: User

Tag: Col Class log means question preserves AAA output style

A string of lowercase letters can be considered as the largest fragment of some same letter. For example, "AAABBAAAC" is made up of the following fragments: ' aaa ', ' BB ', ' C '. Bull Ox now given a string, please help calculate the average length of all fragments of this string.
Input Description:
The input includes a string s, the length of the string s (1≤length≤50), and S contains only lowercase letters (' a '-' Z ')
Output Description:
Outputs an integer that represents the average length of all fragments, rounded to preserve two decimal places. As shown in the example: s = "AAABBAAAC" The average length of all fragments = (3 + 2 + 3 + 1)/4 = 2.25
Input Example 1:
Aaabbaaac
Output Example 1:
2.25
1num =input ()2result = []3size = Len (num)-14Count = 15  forIinchRange (size):6     ifNum[i] = = num[i+1]:7Count + = 18     Else:9 result.append (count)TenCount = 1 One result.append (count) A Print('%.2f'% (sum (result)/len (result)))

"Python exercises" string fragment

Related Article

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.