Docsity

Python Interpreters, Fibonacci Number, Attributes Scripting Languages | ECS 145, Quizzes of Computer Science

Toggle sidebar
bg1
ECS145 Scripting Languages - Spring 2005 Name:
Quiz 1
1. (1pt) List 3 attributes of scripting languages.
2. (4pts) You have been hired by Python Interpreters, Inc. to replace a computer and interpret Python.
Evaluate the following expressions as a python interpreter would.
(a) print 1*2*3
(b) x = range(10)
x.reverse()
print x[6:9]
(c) x = "onetwothree"
print x[5:8] + x[-1] + x[8]
(d) x = "one"
print x*2
3. (3pts) Write a function fib(n) that returns the nth fibonacci number. The nth fibonacci number is
generated by the recurrence relation
fib(n) = fib(nโˆ’1) + fib(nโˆ’2)
where fib(0) = 1 and fib(1) = 1

Partial preview of the text

Download Python Interpreters, Fibonacci Number, Attributes Scripting Languages | ECS 145 and more Quizzes Computer Science in PDF only on Docsity!

ECS145 Scripting Languages - Spring 2005 Name:

Quiz 1

  1. (1pt) List 3 attributes of scripting languages.
  2. (4pts) You have been hired by Python Interpreters, Inc. to replace a computer and interpret Python. Evaluate the following expressions as a python interpreter would.

(a) print 12

(b) x = range(10) x.reverse() print x[6:9]

(c) x = "onetwothree" print x[5:8] + x[-1] + x[8]

(d) x = "one" print x*

  1. (3pts) Write a function fib(n) that returns the nth^ fibonacci number. The nth^ fibonacci number is generated by the recurrence relation

f ib(n) = f ib(n โˆ’ 1) + f ib(n โˆ’ 2)

where f ib(0) = 1 and f ib(1) = 1