A202/A598 Spring 2007 Wed Jan 10 11:15-12:30 LH102 Lecture 2



  1. What is IDLE?


  1. What does raw_input(...) do?


  1. How does print work? What does print, (with a comma) do?


  1. You type (three double quotes) at the IDLE prompt, then hit Enter. What happens? You hit Enter two more times, then type another set of three double quotes and hit Enter again. What happens? Explain.


  1. What characters need to be protected in a string? How do you protect them?


  1. What do + and * mean in the context of string expressions? Give examples.


  1. Evaluate the following expressions:


2 + 3

2 / 3

2 * 3

2 * 3

2 + 3

2 + 3

2 * 3 / 6

3 / 6 * 2


  1. How do you find the length of a string?


  1. Write a short program that reads two integers from the user and adds them up.


  1. What is casting?


  1. Illustrate the use of the string methods upper(), lower(), title(), replace().


  1. Write a program that reads a sentence and removes all vowels in it.


  1. Write a program that reads two integers and prints back the largest of the two. Did you use an if statement? Can you write the program without if statements, just by using +, -, division by 2 and the abs(...) function?


  1. Write a program (called Letter) that translates a number between 0 and 4 into the closest letter grade. For example, the number 2.8 (which might have been the average of several grades) would be converted to B-. Break ties in favor of the better grade; for example 2.85 should be a B.


  1. How do you generate random integers in Python?


  1. What does range(...) do?


  1. Give an example of a list. How can you select random elements from it? Does this work for strings too?


  1. Write a program that produces the first 20 multiples of 3. Explain the program.


  1. How do you access individual characters in a string?


  1. Write a program that reads a string and prints back its characters one per line.


  1. Write a program that reads a string and swaps the first letter with the last.


  1. Write a program that reads a string, reverses it, and prints that back.


  1. Write a program that reads a string and produces all circular permutations of it; for example if the string read is pooh, the program prints the following four strings: pooh, ooph, opho, and phoo.


  1. A bank account starts out with $10,000. Interest is compounded at the end of every month at 6 percent per year (0.5 percent per month). At the beginning of every month, $500 is withdrawn to meet college expenses after the interest has been credited. After how many years is the account depleted?


  1. Now suppose the numbers ($10,000, 6 percent, $500) were user-selectable. Are there values for which the algorithm you developed would not terminate? If so, make sure it always terminates.


  1. Write a program that chooses a random integer between 0 and 100 and lets the user guess it. Each user entry is given feedback (if the user should try higher, lower, or if the guess is right). If the user guesses the number in up to 10 tries the program ends, and the user wins. Otherwise the user loses after the tenth wrong guess and the program reports that too.