diff -r 6c203780bfbe -r c507e9c413c6 parsing_data/questions.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/parsing_data/questions.rst Thu Oct 07 14:40:21 2010 +0530 @@ -0,0 +1,102 @@ +Objective Questions +------------------- + + 1. How do you split the string "Guido;Rossum;Python" to get the words + + Answer: line.split(';') + + 2. line.split() and line.split(' ') are same + + a. True + #. False + + Answer: False + + 3. What is the output of the following code:: + + line = "Hello;;;World;;" + sub_strs = line.split() + print len(sub_strs) + + Answer: 5 + + 4. What is the output of " Hello World ".strip() + + a. "Hello World" + #. "Hello World" + #. " Hello World" + #. "Hello World " + + Answer: "Hello World" + + 5. What does "It is a cold night".strip("It") produce + Hint: Read the documentation of strip + + a. "is a cold night" + #. " is a cold nigh" + #. "It is a cold nigh" + #. "is a cold nigh" + + Answer: " is a cold nigh" + + 6. What does int("20") produce + + a. "20" + #. 20.0 + #. 20 + #. Error + + Answer: 20 + + 7. What does int("20.0") produce + + a. 20 + #. 20.0 + #. Error + #. "20" + + Answer: Error + + 8. What is the value of float(3/2) + + a. 1.0 + #. 1.5 + #. 1 + #. Error + + Answer: 1.0 + + 9. what doess float("3/2") produce + + a. 1.0 + #. 1.5 + #. 1 + #. Error + + Answer: Error + + 10. See if there is a function available in pylab to calculate the mean + Hint: Use tab completion + +Larger Questions +================ + + 1. The file ``pos.txt`` contains two columns of data. The first and second + columns are the x and y co-ordiantes of a particle in motion, respectively. + Plot the trajectory of the particle. + + Answer:: + + x_values = [] + y_values = [] + + for line in open("/home/fossee/pos.txt"); + x_str, y_str = line.split() + x = int(x_str) + y = int(y_str) + + x_values.append(x) + y_values.append(y) + + plot(x, y, 'b.') +