DATA STRUCTURE EXCERCISE 1. Write a python script that ...
[Pages:6]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.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- time series analysis with pandas marquette university
- open source tools for optimization in python
- introduction to python for econometrics github pages
- data handling using pandas 1
- data structure excercise 1 write a python script that
- python for data science cheat sheet lists also see numpy
- data 301 introduction to data analytics python people
- think python green tea press
- python cheat sheet programming with mosh
- solar time and solar time python university of florida