$40
The objective for this assignment is to make sure
• You have a working setup for Python outside linprog. Most of the homeworks and class examples for this class will involve libraries that are not installed on linprog.
• You can write small to medium level programs in Python, using certain built-in data structures (no libraries).
• You can handle console input and output.
1 Program 1 - Palindromes -
Write a Python program to read in a number of strings from the user. Stop when the user enters “Done”. Then check if each of the strings is a palindrome (ignore case and spaces) and throw the palindromic strings into a dictionary, where the key is a counter and the value is the string. Finally, print the dictionary. You can assume that your strings will only contain lower and uppercase letters and spaces Sample Run:
Enter the strings:
taco Cat sWAp paws
Who are you people
Wumbology
Rats live on no evil star
Done
The palindromes are:
{1: ‘taco Cat’, 2: ‘sWAp paws’, 3: ‘Rats live on no evil star’}
2 Program 2 - Pascal’s Triangle -
Write a Python program to print Pascal’s triangle for a certain number of rows. Define a function called printTriangle to print the Pascal’s Triangle with row number of rows. In main, read an integer ‘N’ from the user, call the printTriangle function to print the Pascal’s Triangle.
Pascal’s Triangle is an arithmetic and geometric figure first imagined by Blaise Pascal. To build the triangle, start with “1” at the top, then continue placing numbers below it in a triangular pattern. Each number is the numbers directly above it added together. It is usually written with the rows staggered like in the picture below.
1
You can assume the number entered will be at least 3. You can also just print the triangle like the sample run, instead of staggering the rows. Sample Run:
Enter the number of rows: 8
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1