DATA STRUCTURE EXCERCISE 1. Write a python script that ...

DATA STRUCTURE EXCERCISE

1. Write a python script that accepts an integer n as user input (with empty prompt)

Create a list of integers from 0 to n-1

Print this list

Solution

n=int(input())

L=list(range(n))

print(L)

2. Write a python script that accepts an integer n as user input (with empty prompt)

Store the square of all the odd numbers less than n in a list

Print this list

Example:

Input:

7

Output:

[1, 9, 25]

Solution

n=int(input())

L=[]

for i in range(n):

if(i%2!=0):

L.append(i*i)

print(L)

3. Write a python script that accepts an integer n as user input (with empty prompt)

Store the square of all the odd numbers less than n in a tuple

Print that tuple

Example:

Input:

7

Output:

(1, 9, 25)

Solution

n=int(input())

T=()

for i in range(n):

if(i%2!=0):

T=T +(i*i,)

print(T)

4. Write a python script that accepts an integer, n (>= 1) from the user.

Store the first n numbers of the Fibonnaci series in a list.

Print this list.

Example:

Input:

5

Output:

[0, 1, 1, 2, 3]

Solution

n=int(input())

a=0

b=1

c=a+b

L=[a,b,c]

i=3

while(i ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download