Write a Python program to generate a matrix

Assignment Help Python Programming
Reference no: EM132799559

Python Programming Assignment -

Section 1 - short answers, you should type your answers either in this Word document or as a separate text file such as created in notepad. Neatness and clarity matter in your answer.

1. Given: B = (3.5, 3.7, 5.0, 10.6, 25.3, 50.6)

a. What is wrong with: B[3] = 10.6?

b. Write output for: print('Slice sum = {mySum:06.2f}'.format(mySum=sum(B[-3:1:-1])))

c. Write an equivalent line of code to the above print statement using all positive numbers for slicing.

d. Is a, b, c = B[-1:-5:-1] allowed?

e. If d. is allowed, what is the value of b? If d. is not allowed, correct the statement (by changing only one character) and tell the value of b.

2. True or False: (about Python)

a. A tuple can be redefined within its original scope?

b. Python relies on indentation to define scope in the code?

c. def is a keyword used to identify a block of code that runs only when called?

d. A callback function cannot be defined inside of another function?

e. A lambda function can only take one argument?

3. a. Write a single line of code that will produce a 6×6 identity matrix (list of lists).

b. Modify your line of code from a. to fill all the non-diagonal terms with a formatted string of the form 'r,c' where r is the row index and c is the column index in the matrix. 

Section 2 - solutions problems 4 - 6 should be written in separate Python files titled EX1-4.py, EX1-5.py, EX1-6.py.

4. An exercise in producing pseudorandom numbers, indexing, and data check/verification. Write a Python program to generate a 10×10 matrix filled with random integers in the range of 0 to 100 (without duplicate numbers).

Output your 10×10 matrix to the console in the format:

A=

[82, 18, 74, 50, 33, 16, 8, 92, 60, 85]

[23, 78, 5, 75, 6, 1, 66, 32, 19, 54]

[91, 55, 28, 90, 36, 52, 0, 65, 30, 14]

[79, 9, 63, 94, 58, 96, 24, 71, 64, 37]

[35, 42, 17, 84, 98, 80, 10, 70, 7, 29]

[59, 25, 99, 11, 62, 87, 27, 51, 83, 40]

[81, 4, 41, 3, 2, 76, 26, 39, 73, 88]

[86, 45, 21, 48, 97, 61, 67, 68, 93, 89]

[77, 46, 38, 57, 13, 22, 72, 34, 47, 31]

[95, 44, 12, 53, 69, 15, 49, 20, 56, 43]

Seed values = [1234,19857,25000]

Verified 0 duplicated numbers!

5. a. Use your pseudorandom number generator from question 4 to generate a list of 1000 random floating point numbers between 0 and 1 (duplicates are okay). Consider these values to represent probability levels that can be found by integrating the Gaussian probability density function (PDF) between

x = μ-5⋅σ to x=xi such that pi = P(x<xi|N(μ,σ)).

b. Using your Simpson function (nPoints = 50) to integrate the Gaussian PDF combined with your Secant method, find the set of x values compatible with your list of 1000 probabilities.

c. Finally, calculate the estimates of the population parameters μ and σ2 using the unbiased sample estimators from you set of x values. Compare your values to those from N(175, 15).

Output the values for your population estimators like:

Population mean estimate = y.yy

Population variance estimate = z.zz

6. The following describes a tiny part of the airplane design process - Choosing the engine size needed to meet a take-off distance requirement (STO). STO is the distance an airplane will roll on the runway before it is able to lift off into the air. Calculating STO is performed using a sequence of five equations shown below. Those equations require seven parameters that control takeoff performance. The engine thrust parameter is a major factor in determining take-off distance. The graph shows how take-off distance gets shorter as engine thrust is increased.

1718_figure.jpg

Write a Python program that includes and calls the following three functions:

a) def STO(thrust):

Thrust: the value of the engine thrust. Important, this is the only argument to be passed to this function. All of the other required airplane parameters may be assumed constant. Local variables for those parameters may be defined and assigned values inside the STOfunction. Use the airplane parameter values given in the figure above.

The function returns: the airplane take-off distance, calculated using the five equations given above. The first four of those equations calculate the value of three constants to be used in the fifth equation (VTO, A and B). That fifth equation requires the use of numerical integration. Use your Simpson function to perform the integration.

b) def ThrustNeededForTakeoff(distance):

distance: the required take-off distance. Important, this is the only argument to be passed to this function. All of the other required airplane parameters may be assumed constant. Local variables for those parameters may be defined and assigned values inside the ThrustNeededForTakeofffunction.

The function returns: the engine thrust needed to allow the airplane to take-off in the specified distance. Hint: The ThrustNeededForTakeofffunction behaves as the inverse of the STOfunction. Therefore it must use a root-finding method to find the value of thrust that causes: STO(thrust)-distance = 0. Use your Secant function to solve for this value of thrust.

c) def main():

main() has no arguments and no return value.

main() does the following:

a) calls STO(13000)to calculate the take-off distance for an engine thrust of 13000 pounds. Print the answer with one decimal place, using a nice text label. The nice text label should include the thrust value of 13000 pounds.

b) calls ThrustNeededForTakeoff(1500)to calculate the thrust needed to allow takeoff in 1500 feet. Print the answer with two decimal places, using a nice text label. The nice text label should include the takeoff distance of 1500 feet.

c) calls ThrustNeededForTakeoff(1000)to calculate the thrust needed to allow takeoff in 1000 feet. Print the answer with two decimal places, using a nice text label. The nice text label should include the takeoff distance of 1000 feet.

Attachment:- Python Programming Assignment File.rar

Reference no: EM132799559

Questions Cloud

Evaluate the competencies necessary to work : Summarize the social and business elements of India, including items such as the demographics of the people and society, the government, the economy.
Develop a marketing flyer for a healthcare provider : You may submit a typed paper or a PowerPoint presentation containing the following information: Introduce your provider and provide background information.
Determining the annual renewal rate : Your subscription to Investing Wisely Weekly is about to expire. You plan to subscribe to the magazine for the rest of your life, and you can renew
What is the after-tax cost of new debt : The firm will pay $50 per bond in flotation costs. What is the after-tax cost of new debt if the firm is in the 35% tax bracket?
Write a Python program to generate a matrix : Write a Python program to generate a 10×10 matrix filled with random integers in the range of 0 to 100 (without duplicate numbers)
Estimate the company wacc : Daves Inc. recently hired you as a consultant to estimate the company's WACC. You have obtained the following information.
What is the total number of executions in your state : When did prison overcrowding begin to be a problem in the United States and what was the main issue that caused the overcrowding?
What is expected rate of return : If Richard Dean, an average investor, is considering purchasing this stock at the market price, what is his expected rate of return?
Stockholders expected rate of return : If TC Corp. stock is selling for $50.00 per share, the stockholders' expected rate of return is.

Reviews

Write a Review

Python Programming Questions & Answers

  How will you calculate the shortest distance from device a

How will you calculate the shortest distance from device a to b and device c to b compared to distance directly from a to c.

  Implement the viterbi algorithm

CPS363: Introduction to Bioinformatics - Franklin & Marshall College - implement the Viterbi algorithm and evaluate its effectiveness by experimenting

  Write a program to generate personalized invitations

Write a program to generate personalized invitations for an event using a guest list and event details text documents about event venue.

  Generate the total number of occurrences for each side

You roll the dice 10,000 times. Each time you get one of six sides with a probability of 1/6. You need to generate the total number of occurrences.

  Print out the average score accurate to two decimal places

print out the average score accurate to two decimal places.

  Why members discontinue and thereby reduce attrition

Write an algorithm in structured English pseudocode that describes the steps required to perform the task specified. Run your program using the test data.

  Develop a small game called tryyourluck

Develop a small game called TryYourLuck. It selects a random integer number between 1 and 9 and compares this number with the integer number.

  Define a class for representing a distance

Define a class for representing a distance (with one attribute that represents the distance in inches).

  Create a function calledlocker to find your answer

Solve the "locker puzzle." A school has 100 students and 100 lockers. All lockers are closed on the first day of school. As the students enter.

  FIT5196 Data wrangling Assignment

FIT5196 Data wrangling Assignment Help and Solution, Monash University - Assessment Writing Service - write Python code to integrate several datasets

  Console program where you will implement

Create a console program where you will implement coding constructs and variables that are needed for this program and will implement the code within Main and any required static methods.

  Aussie best car abcdeclares that based on its yearly sales

aussie best car abcdeclares that based on its yearly sales it will award a bonus as follows. the bonus will be equally

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd