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

Quiz 4 for the cosc 235 course taught by david a. Sykes in the fall 2008 semester. The quiz covers topics such as data types and string manipulation in python. Students are required to identify the data types of certain expressions and write code segments to perform specific tasks.

Typology: Quizzes

Pre 2010

Uploaded on 08/18/2009

koofers-user-exm
koofers-user-exm ๐Ÿ‡บ๐Ÿ‡ธ

9 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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.