Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CS 235A Quiz #1: Python Identifiers and Operations - Prof. Joseph D. Sloan, Quizzes of Computer Science

A quiz from a cs 235a course held in spring 2007. The quiz covers various topics such as valid python identifiers, arithmetic operations, string functions, and list generation. Students are required to indicate whether given identifiers are valid, perform arithmetic operations, and write code to generate lists.

Typology: Quizzes

Pre 2010

Uploaded on 08/16/2009

koofers-user-upw-1
koofers-user-upw-1 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 235A Quiz #1: Page 1 of 4
COSC235A Spring 2007
Test #1
Please read each question carefully and be sure to give complete answers. Work quickly
and good luck!
1. (1 pt.) Print your name: ___________________________________________
2. (10 pts.) For each of the follow, indicate whether it is a valid Python identifier or
explain in two or three words why it isn’t.
a) 2007TaxRate
b) return
c) Inflation_Rate
d) _example2
e) Tax+Increase
3. (10 pts.) What are the results of each of the following operations?
a) 2 + 3**2
b) 12 / 10 + 7 % 10
c) 3.0 / 4.0 + 3 / 4
d) math.floor(7.9)
e) math.ceil(–2.1)
pf3
pf4

Partial preview of the text

Download CS 235A Quiz #1: Python Identifiers and Operations - Prof. Joseph D. Sloan and more Quizzes Computer Science in PDF only on Docsity!

COSC235A Spring 2007

Test

Please read each question carefully and be sure to give complete answers. Work quickly

and good luck!

1. (1 pt.) Print your name: ___________________________________________

2. (10 pts.) For each of the follow, indicate whether it is a valid Python identifier or

explain in two or three words why it isn’t.

a) 2007TaxRate

b) return

c) Inflation_Rate

d) _example

e) Tax+Increase

3. (10 pts.) What are the results of each of the following operations?

a) 2 + 3**

b) 12 / 10 + 7 % 10

c) 3.0 / 4.0 + 3 / 4

d) math.floor(7.9 )

e) math.ceil(–2.1)

4. (4 pts.) If I want to use string functions like upper() and split(), what statement

must I include in my code so I can have access to these function?

5. (4 pts.) How would you convert the string “23.45” into a floating point number?

6. (6 pts.) Convert 101112 to decimal showing your work.

7. (6 pts.) Convert 5710 to binary showing your work.

8. (6 pts.) Write a Python expression to evaluate 2

x

x

x

9. (10 pts.) Given st1 = “quintessential”. What will the following return?

a) st1[:]

b) st1[1:2]

c) st1[5]

d) st1[– 3 :]

e) st1[3:–3]

13. (8 pts.) Write a function ft2cm() to convert from feet to centimeters. (There are

2.54 centimeters in an inch.) For example, ft2cm(3) would return 91.44.

14. (8 pts.) Using ord() and chr(), write a function next() that will take a letter and

return the next letter in the collating sequence. For example, next(“G”) would

return “H”. (You don’t need to worry about what comes after “Z”.)

15. (8 pts.) Write an interactive program printReverse() that prompts the user to

enter a string and then loops over the string printing it in reverse. For example, if the

user enters Hello, the program will display olleH. (You don’t need to worry about

any extra spaces print may insert.)

Pledged: ________________________________________________________________