Vous êtes sur la page 1sur 17

Python Tutorial

EE677 Foundations of VLSI CAD

Contents
Basic Example : Fibonacci
List
Dictionary
Function (Fibonacci example with function)
Fibonacci with memoization (modify existing code)
Classes
Find topological order using AAT recursive (unit delay, and sort by AATs)
RAT recursive (first generate fanout lists from fanin lists)
Source: http://interactivepython.org/runestone/static/pythonds/Introduction/GettingStarted.html

Fibonacci - Basic example


Print statements
For loops
Indentation for for/if
Commenting precedes with #

List : Concept and Methods


A list is an ordered collection of zero or more references to Python data
objects. Lists are written as comma-delimited values enclosed in square
brackets. The empty list is simply [ ].

List : Demo
Refer to list_demo.py

Lists: Exercise
If you do not feel comfortable with lists, refer the lists section in the link
Write a python script using Lists to do the following tasks and discuss your
results:
1.
2.
3.

Create 2 lists (A & B) with 5 entries of numbers that are multiples of the
last 2 digits of your roll no.
Join the list and remove duplicate occurrences of elements in the joined
list - List1
Copy this created list into another list (List2) and remove the elements
that are lesser than the mean of the List1; print List1 and List2

Print the output in each case and analyse the results

Dictionary : Concept and Methods


Dictionaries are collections of associated pairs of items where each pair
consists of a key and a value. This key-value pair is typically written as
key:value

Dictionary : Demo
Refer to dict_demo.py

Dictionary: Exercises
If you do not feel comfortable with lists, refer the lists section in the link
Write a python script using Dictionary to do the following tasks and discuss
your results:
1.
2.
3.

Create a dictionary with 5 entries of your friends roll numbers indexed


with their names as keys
Sort the dictionary alphabetically and save as a list
Remove the entry of your best friends roll number

Functions
Analogous to functions in C/C++
Syntax:

Arguments are passed by reference

Using Functions
Refer to the example function_example.py given

Functions - Argument Passing


Please run the script function_ref.py in your python console
Observe the output, Is it different? If so, Why?

Classes
Analogous to classes in C++
Syntax

Inheritance
Use same data members and functions as of parent class
Parent:

Child:
#Call superclass const.

Inheritance
1.

Use classes for calculating angle between 2 vectors in x-y coordinate


system.

2.

Use inheritance to transform vectors from cartesian to polar coordinate


system.

AAT and topological sort exercise


Find the topological sort by calculating the AAT with unit delay at all the nodes
Refer to file: aat_recursive_exercise.py

RAT exercise
Given the AAT_recursive code and an RAT of 20 at the final node, write a
Python script to find the RAT at all the nodes of the same graph

Vous aimerez peut-être aussi