Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Lab Exercises: Question #1 Using Python's string capabilities, loops, lists, and built-in functions, write the code for a Python user-defined function that displays 'n' rows

Lab Exercises: Question #1 Using Python's string capabilities, loops, lists, and built-in functions, write the code for a Python user-defined function that displays 'n' rows of a Pascal's Triangle! The function prototype MUST be: def drawPascals(n) Each row begins with the number 1 and contains exactly m numbers (where m is the row number). So that, when m is 1, there is 1 number, when m is 2, there are 2 numbers, when m is 5, there are 5 numbers, etc. After the first number in each row, each subsequent number is derived from the sum of the 2 numbers in the PREVIOUS row starting at that number's exact index and moving to the left to get the 2nd value. For example, with a 5 row Pascal triangle: 1 | +-+ | 1 1 | | +-+ | 1 2 1 | | +-+ | 1 3 3 1 | | +-+ | 1 4 6 4 1 the numbers on row 5: (1, 4, 6, 4, 1) are derived by examining the 2 numbers immediately above and to the left on the previous row for the number being generated! If only 1 number is available, assume the second number is 0. When the "middle" number in each row is reached, the remaining numbers in each row consist of the reverse set of all previous numbers excluding the middle number. You must take care therefore to make a distinction between even and odd number rows when determining the middle value. So, for example, a Pascal's Triangle with 4 rows would be: 1 1 1 1 2 1 1 3 3 1 So, for example, a Pascal's Triangle with 8 rows would be: 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 For more information about Pascal's Triangle, visit: https://medium.com/i-math/top-10-secrets-of-pascals-triangle-6012ba9c5e23 Question #2 Write a Python user-defined function that accepts a string of any length and first displays the string followed by a newline followed by a horizontal\ frequency graph of only lowercase ALPHABETIC letters in the string (in alphabetical order). Spaces and all non-alphabetic characters are to be ignored! The function prototype MUST be: def lcFrequency(userString) For example, the function call: lcFrequency("This is a Python test 123!") would display: This is a Python test 123! a=1 * e=1 * h=2 ** i=2 ** n=1 * o=1 * s=3 *** t=3 *** y=1 * HINT: Consider using Python's upper( ), lower( ), and ord( ) functions and string.ascii_lowercase to complete your solution. Question #3 Write a Python user-defined function that accepts a string and a number 'n' representing a shift index and encrypts the string by substituting (ciphering) each alphabetic letter by increasing it by n (wrapping around to the beginning of the alphabet when required). The function prototype MUST be: def charShifter(userString, n) For example, if the string was: "abc-xyz", and the shift value was: 3, then the function call: charShifter("abc-xyz", 3) would display and return the encrypted string: "def-abc" For more information, please visit this link: https://en.wikipedia.org/wiki/Caesar_cipher MAIN PROGRAM: Your solution may ONLY use the python modules listed below # program: L2main.py # author: danny abesdris # date: january 24, 2023 # purpose: python main( ) program for PRG550 WINTER 2023 Lab #2 import math import random import string import collections import datetime import re import time import copy  def drawPascals(n) : your code here... # end def def lcFrequency(userString) : your code here... # end def def charShifter(userString, n) : your code here... # end def  def main( ) : myStr = """ You're an interesting species, an interesting mix. You're capable of such beautiful dreams and such horrible nightmares. You feel so lost, so cut off, so alone, only you're not. See, in all our searching, the only thing we've found that makes the emptiness bearable is each other. Contact --1997--""" for i in range(1, 20, 4) : drawPascals(i) lcFrequency(myStr) for i in list([2, 10, 25, 26, 1000, 13]) : charShifter(myStr, i) # end main( ) if __name__ == "__main__" : main( ) The OUTPUT should be EXACTLY as displayed below: 1 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 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 1 8 28 56 70 56 28 8 1 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 1 8 28 56 70 56 28 8 1 1 9 36 84 126 126 84 36 9 1 1 10 45 120 210 252 210 120 45 10 1 1 11 55 165 330 462 462 330 165 55 11 1 1 12 66 220 495 792 924 792 495 220 66 12 1 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 1 8 28 56 70 56 28 8 1 1 9 36 84 126 126 84 36 9 1 1 10 45 120 210 252 210 120 45 10 1 1 11 55 165 330 462 462 330 165 55 11 1 1 12 66 220 495 792 924 792 495 220 66 12 1 1 13 78 286 715 1287 1716 1716 1287 715 286 78 13 1 1 14 91 364 1001 2002 3003 3432 3003 2002 1001 364 91 14 1 1 15 105 455 1365 3003 5005 6435 6435 5005 3003 1365 455 105 15 1 1 16 120 560 1820 4368 8008 11440 12870 11440 8008 4368 1820 560 120 16 1 You're an interesting species, an interesting mix. You're capable of such beautiful dreams and such horrible nightmares. You feel so lost, so cut off, so alone, only you're not. See, in all our searching, the only thing we've found that makes the emptiness bearable is each other. Contact --1997-- a = 17 ***************** b = 5 ***** c = 8 ******** d = 3 *** e = 31 ******************************* f = 6 ****** g = 5 ***** h = 11 *********** i = 14 ************** k = 1 * l = 11 *********** m = 5 ***** n = 18 ****************** o = 19 ******************* p = 3 *** r = 13 ************* s = 17 ***************** t = 18 ****************** u = 11 *********** v = 1 * w = 1 * x = 1 * y = 3 *** Aqw'tg cp kpvgtguvkpi urgekgu, cp kpvgtguvkpi okz. Aqw'tg ecrcdng qh uwej dgcwvkhwn ftgcou cpf uwej jqttkdng pkijvoctgu. Aqw hggn uq nquv, uq ewv qhh, uq cnqpg, qpna aqw'tg pqv. Ugg, kp cnn qwt ugctejkpi, vjg qpna vjkpi yg'xg hqwpf vjcv ocmgu vjg gorvkpguu dgctcdng ku gcej qvjgt. Eqpvcev --1997-- Iye'bo kx sxdobocdsxq czomsoc, kx sxdobocdsxq wsh. Iye'bo mkzklvo yp cemr lokedspev nbokwc kxn cemr rybbslvo xsqrdwkboc. Iye poov cy vycd, cy med ypp, cy kvyxo, yxvi iye'bo xyd. Coo, sx kvv yeb cokbmrsxq, dro yxvi drsxq go'fo pyexn drkd wkuoc dro owzdsxocc lokbklvo sc okmr ydrob. Myxdkmd --1997-- Xnt'qd zm hmsdqdrshmf rodbhdr, zm hmsdqdrshmf lhw. Xnt'qd bzozakd ne rtbg adztshetk cqdzlr zmc rtbg gnqqhakd mhfgslzqdr. Xnt eddk rn knrs, rn bts nee, rn zknmd, nmkx xnt'qd mns. Rdd, hm zkk ntq rdzqbghmf, sgd nmkx sghmf vd'ud entmc sgzs lzjdr sgd dloshmdrr adzqzakd hr dzbg nsgdq. Bnmszbs --1997-- You're an interesting species, an interesting mix. You're capable of such beautiful dreams and such horrible nightmares. You feel so lost, so cut off, so alone, only you're not. See, in all our searching, the only thing we've found that makes the emptiness bearable is each other. Contact --1997-- Kag'dq mz uzfqdqefuzs ebqouqe, mz uzfqdqefuzs yuj. Kag'dq ombmnxq ar egot nqmgfurgx pdqmye mzp egot taddunxq zustfymdqe. Kag rqqx ea xaef, ea ogf arr, ea mxazq, azxk kag'dq zaf. Eqq, uz mxx agd eqmdotuzs, ftq azxk ftuzs iq'hq ragzp ftmf ymwqe ftq qybfuzqee nqmdmnxq ue qmot aftqd. Oazfmof --1997-- Lbh'er na vagrerfgvat fcrpvrf, na vagrerfgvat zvk. Lbh'er pncnoyr bs fhpu ornhgvshy qernzf naq fhpu ubeevoyr avtugznerf. Lbh srry fb ybfg, fb phg bss, fb nybar, bayl lbh'er abg. Frr, va nyy bhe frnepuvat, gur bayl guvat jr'ir sbhaq gung znxrf gur rzcgvarff ornenoyr vf rnpu bgure. Pbagnpg --1997--

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions