========= project00 ========= Replace ??? with your answer and turn it in as follows: > turnin --submit hyukcho project00 project00.txt You can check out details of "turnin" in a couple of ways: (1) just type "turnin" in the commandline of any UTCS linux/unix machines, or (2) just check out the following URL: http://www.cs.utexas.edu/users/hyukcho/AI/cs105_fall_2007/turnin.html (00) How to run python? > ??? Python 2.4.3 (#1, Aug 2 2006, 22:24:22) [GCC 3.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> (01) Let's do the followings: >>> 1 + 5 ??? >>> 2 * 5 ??? >>> 1 / 2 ??? >>> (02) Is it the right answer? Then, do the followings: >>> float(1 / 2) ??? >>> 1 / 2.0 ??? >>> float(1)/2 ??? >>> 1 / float(2) ??? >>> (03) How about these? >>> 'aaa' ??? >>> len('aaa') ??? >>> (04) What happened? Read carefully the error message (if you have), and explain it. >>> len('aaa') + len('bbb') ??? >>> len('aaa') + len('bbb') + 4 ??? >>> 'aaa' + 'bbb' ??? >>> 'aaa' + 5 ??? ??? ??? >>> (05) How to protect you from this kind of problem? >>> type(1) ??? >>> type('1') ??? >>> type(1.0) ??? >>> (06) You can associate a name to a value: >>> a = 10 >>> a ??? >>> (07) The interpreter displays the value (10) of the variable (a). Read carefully the error message (if you have), and explain it. >>> myVar = 'one sentence' >>> myVar ??? >>> 1string = 'one string' ??? ??? ??? ??? >>> >>> myvar ??? ??? ??? >>> (08) What appended? >>> a = 2 >>> a ??? >>> a * 5 ??? >>> b = a * 5 >>> b ??? >>> a = 1 >>> b ??? >>> (09) Why hasn't b changed? What is the difference between the followings: >>> b = a * 5 ??? >>> b = 5 ??? (10) What is the differerence between the followings: What do you conclude about the type of a variable? >>> a = 1 #in this case a is a number >>> a + 2 ??? >>> a = '1' #in this case a is a string >>> a + 1 ??? ??? ??? >>> (11) The following will be explained later: >>> from string import * ??? (12) Can we perform calculus on strings? >>> myString='abc' >>> myString * 3 ??? >>> myString1 = 'abcdefghijklmnopqr' >>> myString2 = 'ggghhhiiijjjkkklll' >>> (13) How do you concatenate myString1 and myString2 in a single string? >>> myString = myString1 + myString2 ??? >>> (14) What is the length of the string myString? >>> len(myString) ??? >> (15) Does the string myString contain the character 'c'? >>> 'c' in myString ??? >>> (16) Does it contain 'm'? >>> 'm' in myString ??? >>> (17) Do the followings: And explain why. >>> myString[0] ??? >>> myString[1] ??? (18) Display the 10th character. >>> myString[9] ??? (19) Find the index of the last character. >>> len(myString) ??? >>> myString[35] ??? >>> (20) Find a more generic way to do it. >>> myString[len(myString) - 1] ??? (21) Python provides a special form to get the characters from the end of a string: >>> myString1[-1] ??? >>> myString1[-4] ??? >>> (22) Do the following, then what do you get? >>> myString1[0] + myString1[5] + myString1[10] ??? >>> (23) Python provides a form to get 'slices' from strings: >>> myString[0:3] ??? >>> myString[3:6] ??? (24) How many of the character does this string contain? >>> count(myString, 'a') ??? >>> count(myString, 'c') ??? >>> count(myString, 'k') ??? >>> count(myString, 'l') ??? >>> (25) Count the percentage of 'k' on the string myString. >>> totalCount = len(myString) >>> localCount = count(myString, 'k') >>> percentage = (localCount / totalCount) * 100 >>> percentage ??? (26) What happened? Can you correct this? >>> ??? (27) How to find specific pattern on a string: Do the following and explain why? >>> myString = """abcdefghijklmnopqrstuvwxyz ??? >>> myString1 = 'ABCDEF' >>> myString2 = 'FEDCAB' >>> count(myString, myString1) ??? >>> >>> 'abcdef' == 'abcdef' ??? >>> 'abcedf' == 'ABCDEF' ??? >>> (28) How to change the case of a string? >>> myString11 = lower(myString1) >>> myString11 ??? >>> count(myString, myString11) ??? >>> (29) Display the string myString. Do you see a character that you don't expect to have in myString? Then, how to remove it? >>> myString 'abcdefghijklmnopqrstuvwxyz\nzyxwvutsrqponmlkjihgfedcba' >>> len(myString) ??? >>> myString = replace(myString, '\n', '') >>> myString 'abcdefghijklmnopqrstuvwxyzzyxwvutsrqponmlkjihgfedcba' >>> len(myString) ??? (30) How to exit Python shell? >>> ???