If Statements
Example: What is the output of the following program? x = 9 y = 2 if x/y>4: print "if" else: print "else" print "freedom" Practice I: Maximum of 3 integers Our first task is to write a program, which asks the user to input 3 integers and outputs the maximum of them.
String Operations
Consider the following string:
What would the following expressions produce?
Given x, provide a way to access "you" with negative indices Practice II : Strings Creating String expressions Execute the following statements in Python:import string str1 = "Go" str2 = "Terriers!"Now, for each of the following values, construct a Python expression involving string operations on str1 and/or str2 that evaluates to that
value.
Using the "in" keyword Consider the following expression:
What is the type of this expression?
Reading strings from the terminal Assume that the following raw_input statements are both executed:
Write one or more statements that prints the sum of our (mine and yours) favorite numbers! (Hint: Don't forget that raw_input always gives you a string. How can you change the string to an integer?)
Printing vertically Write a program to read a word into the variable word and print each letter of the word twice on its own line. Example: if the user inputs "CS", the output should be: C C S S
Splitting strings Useful functions from the string library:
Is What about >>> string.replace(temp, " ", ";") |