Docsity

Quiz 4 for COSC 235, Fall 2008 by David A. Sykes - Prof. David A. Sykes, Quizzes of Computer Science

Toggle sidebar
bg1
COSC$235,$Fall$2008$ $ David$A.$Sykes$
Name:$_____________________________$ $ Pledged:$_____________________________$
Quiz%4%
Se pte mber (26,(2008(
1. Show$the$type$(int,$long,$str,$list,$float)$of$the$result$of$each$of$the$expressions.#
5280 / 3280
string.split("apple banana cherry")
5280 / 3280.839
string.join([โ€˜1โ€™, โ€˜IIโ€™, โ€˜Cโ€™])
len("apple banana cherry")
"apple banana cherry"[:5]
$
2. Show$the$output$of$the$following$code$segment.$
s = "1 10 100"
t = string.split(s)
a = ""
b = 0
for item in t:
a = a + item
b = b + int(item)
print "a = %s, b = %s." % (a, b)
3. Write$a$code$segment$to$open$a$file$named$popdata.txt$and$display$the$lines$in$it.$For$an$extra$challenge,$
print$a$line$number$before$each$line$using$three$print$positions$for$the$number$and$a$space$after$the$
number.$
$
$

Partial preview of the text

Download Quiz 4 for COSC 235, Fall 2008 by David A. Sykes - Prof. David A. Sykes and more Quizzes Computer Science in PDF only on Docsity!

COSC 235, Fall 2008 David A. Sykes Name: _____________________________ Pledged: _____________________________

Quiz 4

September 26 , 2008

1. Show the type (int, long, str, list, float) of the result of each of the expressions. 5280 / 3280 string.split("apple banana cherry") 5280 / 3280. string.join([โ€˜1โ€™, โ€˜IIโ€™, โ€˜Cโ€™]) len("apple banana cherry") "apple banana cherry"[:5]

  1. Show the output of the following code segment. s = " 1 10 100 " t = string.split(s) a = "" b = 0 for item in t: a = a + item b = b + int(item) print "a = %s, b = %s." % (a, b)
  2. Write a code segment to open a file named popdata.txt and display the lines in it. For an extra challenge, print a line number before each line using three print positions for the number and a space after the number.