# COP 4521 Homework 1 SOLVED

\$30.00

Category:

COP 4521
Homework 1
Total Points: 10

1 Objective
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.
Please name your files Palindromes.py and Pascal.py. Turn them in through a single submission on Canvas.
After attaching one file, please click “Attach Another File” and incudle the second one as well.
2 Program 1 – Palindromes – 5 points
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’}
3 Program 2 – Pascal’s Triangle – 5 points
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
4 Generic Guidelines
• Add a comment with your name, FSUID, the due date and the line “The program in this file is the individual
work of <your name>” on both files.
• If we have listed a specification and allocated point for it, you will lose points if that particular item is
missing from your code, even if it is trivial.
• Your program should load and run without issues. Every interpretation error will result in a loss of 5 points.
• You are restricted to standard Python (it should run on linrprog. No third party libraries.
• Testing your program thoroughly is a part of writing good code. We give you sample runs to make sure
you match our output requirements and to get a general idea of how we would test your code.
• Only a file turned in through Canvas counts as a submission. A file on your computer, even if it has not
been edited after the deadline, does not count.