Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Each function should be well-commented, including an initial comment that (1) describes the purpose of the function, (2) explains each of the parameters, including the

Each function should be well-commented, including an initial comment that (1) describes the purpose of the function, (2) explains each of the parameters, including the type of each parameter, and (3) explains the value returned by the function, including its type.

This lab will be graded on both the correctness of your functions as well as coding style. Coding style includes commenting, but also good formatting and proper use of various constructs in the Python language.

Hint: recall that python files can be imported as modules, so you can test all of your code from a separate python program using import lab6. Then, for example, you could call the function from question 1 using lab6.num_passwords(94, 2).

  1. [3 points] Passwords can be made up of 52 lower- and upper-case letters, 10 digits, and 32 symbols. In total, there are 94 valid characters that can make up passwords for most websites and operating systems. That means, there are 94 1-character passwords, 94*94 = 8836 2-character passwords, and 94i i-character passwords. Write a function num_passwords that takes two input parameters, chars and n, and returns the total number of passwords up to length n using chars possible characters. For example, num_passwords(94, 2) should return 8836. Experiment with this function to see the importance of both long passwords as well as mixing letters, numbers, and symbols. (e.g., how many fewer possible passwords are there when symbols are excluded?)
  2. [3 points] Write a function named estimate_population that takes three input parameters: the rate of population change as a decimal, an initial population, and a number of years to estimate. This function should return a population estimate using the following rule: Pt+1 = Pt + rate * Pt. That is, the population of the next year is equal to the previous years population plus the previous years population times the rate. Your function will need to repeat this calculation multiple times, as specified by the number of years to estimate. For example, estimate_population(0.0111, 7.5e9, 3) should return 7,752,532,482.
  3. [3 points] Write a function num_digits that takes one input parameter, an integer, and returns the number of digits in that integer. For example, if we were to call num_digits(5132981) it would return 7 because there are 7 digits in 5132981. Hint: this is similar to the checksum program.
  4. [3 points] The * operator can be applied to a string and an integer. For example, 'Z' * 5 evaluates to ZZZZZ. Write a function named draw_triangle that takes one input parameter and prints a triangle pattern of asterisks. For example, if the function argument is 6, then the function produces eleven rows of asterisks where the first row has one asterisk and the sixth row has six asterisks and the eleventh row has one asterisk as in the sample output below.

*

**

***

****

*****

******

*****

****

***

**

*

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

More Books

Students also viewed these Databases questions