0% found this document useful (0 votes)
122 views1 page

Python科學計算第一次作業

This document provides 3 problems to solve using Python for a scientific computing homework assignment. The first problem is to count the number of vowels in a string. The second problem is to count the number of times the string "bob" occurs in a string. The third problem (optional bonus problem) is to find the longest substring in alphabetical order within a string.

Uploaded by

王和盛
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views1 page

Python科學計算第一次作業

This document provides 3 problems to solve using Python for a scientific computing homework assignment. The first problem is to count the number of vowels in a string. The second problem is to count the number of times the string "bob" occurs in a string. The third problem (optional bonus problem) is to find the longest substring in alphabetical order within a string.

Uploaded by

王和盛
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Python 科學計算第一次作業

Problem 1

Assume s is a string of lower case characters.


Write a program that counts up the number of vowels contained in the string s . Valid vowels are:
' a ', ' e ', ' i ', ' o ', and ' u '. For example, if s = 'azcbobobegghakl' , your program should print:
Number of vowels: 5

Problem 2

Assume s is a string of lower-case characters.


Write a program that prints the number of times the string 'bob' occurs in s . For example, if s =
'azcbobobegghakl' , then your program should print

Number of times bob occurs is: 2

Problem 3 (Bonus, 有點難度,可寫可不寫。)

Assume s is a string of lower case characters.


Write a program that prints the longest substring of s in which the letters occur in alphabetical
order. For example, if s = 'azcbobobegghakl' , then your program should print
Longest substring in alphabetical order is: beggh

In the case of ties, print the first substring. For example, if s = 'abcbcd' , then your program
should print
Longest substring in alphabetical order is: abc

Note: This problem may be challenging. We encourage you to work smart. If you've spent more
than a few hours on this problem, we suggest that you move on to a different part of the course. If
you have time, come back to this problem after you've had a break and cleared your head.

You might also like