problem set 1

4
TIPS ON YOUR FIRST ASSIGNMENTS: 1. Please search for similar forum posts before you ask your question! Reply to an already existing discussion. This helps organize responses and it makes it easier for the staff and other students to help you. edX has the neat feature that shows the discussion relevant to a page at the bottom of a lecture, finger exercise or problem set page. Just click the Show Discussion link to see what other students have been posting. 2. Remember, do not post large amounts of code in the forums. This is a violation of the honor code. If you post more than 5-6 lines of code, the staff will edit your post to remove the code. This will make it hard for others to help you. Limit yourself to a few lines of code and an english explanation of what you're trying to do. 3. If you submit code (by clicking Check) and find you get an Incorrect answer, use the See Full Output link to the right of the red "X Incorrect". It will show you the test cases that ran. It will print what your code outputted and what our code outputted. They must match exactly, so double check capitalization, spaces, and general formatting. Finger exercises may be submitted as many times as you want, so if you get an answer wrong, try again! Problem Sets have a limited number of attempts so make sure your code is correct (in your own development environment, like Canopy) before you submit it. 4. If you code an infinite loop and your program sits for a few seconds without printing anything out, restart the console. o You can do this in Canopy by click Ctrl + . (Ctrl key and the period on your keyboard). Or go to the menu Run -> Restart Kernel. If this doesn't work, restart Canopy. o You can do this in IDLE by clicking Ctrl + F6 or by going to the menu Shell -> Restart Shell 5. A Problem Set may have more than one part to submit. Navigate using the film-strip-like bar at the top of the page to go from one component to the next. This is no different than how you have been viewing the lectures and finger exercises.

Upload: george-msenoir

Post on 20-Oct-2015

367 views

Category:

Documents


1 download

DESCRIPTION

course 600cx

TRANSCRIPT

Page 1: Problem Set 1

TIPS ON YOUR FIRST ASSIGNMENTS:

1. Please search for similar forum posts before you ask your question! Reply to an already

existing discussion. This helps organize responses and it makes it easier for the staff and other

students to help you. edX has the neat feature that shows the discussion relevant to a page at the

bottom of a lecture, finger exercise or problem set page. Just click the Show Discussion link to

see what other students have been posting.

2. Remember, do not post large amounts of code in the forums. This is a violation of the honor

code. If you post more than 5-6 lines of code, the staff will edit your post to remove the code.

This will make it hard for others to help you. Limit yourself to a few lines of code and an english

explanation of what you're trying to do.

3. If you submit code (by clicking Check) and find you get an Incorrect answer, use the See Full

Output link to the right of the red "X Incorrect". It will show you the test cases that ran. It will

print what your code outputted and what our code outputted. They must match exactly, so double

check capitalization, spaces, and general formatting. Finger exercises may be submitted as many

times as you want, so if you get an answer wrong, try again! Problem Sets have a limited number

of attempts so make sure your code is correct (in your own development environment, like

Canopy) before you submit it.

4. If you code an infinite loop and your program sits for a few seconds without printing anything

out, restart the console.

o You can do this in Canopy by click Ctrl + . (Ctrl key and the period on your

keyboard). Or go to the menu Run -> Restart Kernel. If this doesn't work, restart

Canopy.

o You can do this in IDLE by clicking Ctrl + F6 or by going to the menu Shell ->

Restart Shell

5. A Problem Set may have more than one part to submit. Navigate using the film-strip-like bar

at the top of the page to go from one component to the next. This is no different than how you

have been viewing the lectures and finger exercises.

Page 2: Problem Set 1

Counting Vowels

(10 points possible)

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

For problems such as these, do not include raw_input statements or define the variable s in any

way. Our automating testing will provide a value of s for you - so the code you submit in the

following box should assume s is already defined. If you are confused by this instruction, please

review L4 Problems 10 and 11 before you begin this problem set.

1

# Paste your code into this box

Status: Unanswered

unsubmitted

Page 3: Problem Set 1

Counting bobs

(15 points possible)

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

For problems such as these, do not include raw_input statements or define the variable s in any

way. Our automating testing will provide a value of s for you - so the code you submit in the

following box should assume s is already defined. If you are confused by this instruction, please

review L4 Problems 10 and 11 before you begin this problem set.

1

# Paste your code into this box

Status: Unanswered

unsubmitted

Page 4: Problem Set 1

Alphabetical Substrings

(15 points possible)

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

For problems such as these, do not include raw_input statements or define the variable s in any

way. Our automating testing will provide a value of s for you - so the code you submit in the

following box should assume s is already defined. If you are confused by this instruction, please

review L4 Problems 10 and 11 before you begin this problem set.

Note: This problem is fairly 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.

1

# Paste your code into this box

Status: Unanswered

unsubmitted