Description
Aim: Introduce you to programming in Python quickly!
Let’s get started!
-
-
Create a directory structure to hold your work for this course and all the subsequent labs:
-
Suggestion: CS202/Lab5
-
-
Python Basics
-
-
For this part, refer to Python Basics.pdf
-
-
Note: This part has been adapted from : https://www3.ntu.edu.sg/home/ehchua/programming/webprogramming/Python1_Basics.html
-
Considering that you all have decent amount of experience with programming in C, C++ and now in Java and Perl, you are only expected to run through the above document quickly. Try to focus on differences from other languages!
-
-
Once you are comfortable with the basics, attempt the following exercises.
-
Exercise 1:
-
-
Write a program (using functions!) that asks the user for a long string containing multiple words. Print back to the user the same string, except with the words in backwards order. For example, say I type the string: My name is Michele Then I would see the string: Michele is name My shown back to me.
-
-
-
Create and save this program in a file named ReverseString.py
-
Exercise 2:
-
-
Write a Python function that prints out the first ‘n’ rows of Pascal’s triangle. Sample Pascal’s triangle is shown below:
-
-
Create and save this program in a file named PascalTriangle.py
-
Write a program (function!) that takes a list and returns a new list that contains all the elements of the first list minus all the duplicates.
-
-
Write two different functions to do this – one using a loop and constructing a list, and another using sets (call these functions RemDupLoop and RemDupSet)
-
-
-
Create and save this program in a file named RemoveDuplicates.py
-
Submitting your work:
-
-
All source files as one tar-gzipped archive.
-
-
-
-
When unzipped, it should create a directory with your ID. Example: 2008CSB1001 (NO OTHER FORMAT IS ACCEPTABLE!!! Case sensitive!!!)
-
-
-
-
-
Negative marks if the TA has to manually change this to run his/her scripts!!
-
-
-
Source files should include the following: (Case-Sensitive file names!!)
ReverseString.py [5 Points]
-
RemoveDuplicates.py [5 Points]
-
PascalTriangle.py [5 Points]
-
Negative marks for any problems/errors in running your programs
-
Submit/Upload it to Google Classroom