Questions
(+30) Write a python program per the following specifications: Populate an array(list) of size 50 randomly...

(+30) Write a python program per the following specifications:

  1. Populate an array(list) of size 50 randomly with only integers 0 and 1
  2. Repeat step1 n = 1000 times using either a while loop or a for loop

At this point you should have a total of 50000 observations

  1. Display the number of 0’s (use the count() function from prior labs)
  2. Display the number of 1’s (use the count() function from prior labs)
  3. Using the Binomial distribution formulas
    1. Display the expected mean (average) of the 1’s == n*size*.5
    2. Calculate and display the standard deviation (SD)

NOTE: sd should be > 100

    1. Display the range as follows:   mean + SD mean - SD
  1. Answer the question: is the total number of 1’s from 4 above. within the range as calculated in 5.c by printing

                                     ‘Yes’ if it is within the range calculated in 5c

                                     ‘No’   if it is not

  1. Display the n*size (== 50000) integers 50 integers per line That is, display the integers in myList 50 per line for 1000 lines See sample output
  2. Display the average of all n*size == 50000 integers (should be < 1 by adding the answers from 3 and 4 above and divide by n*size

my work:

import random
import math
myArray=[]
a=0
b=1
size= 50
j=0
n=1000
#populate array with size=50 random integers in range 0-1 and repeat for 1000 times
while(j<n):
for k in range(size):
randNum=random.randint(a,b)
myArray.insert(k,randNum)
j=j+1
#display array size
print("size of my array is ",len(myArray))
#print myArray 50 values per line
k=0
sub=[]
while(k<len(myArray)):
sub=myArray[k:k+50]
print("...",k,sub)
k=k+50

#count no. of ones and zeroes
zeros=0
ones=0
i=0
while(i<len(myArray)):
if(myArray[i]==1):
ones=ones+1
else:
zeros=zeros+1
i=i+1

print("number of 1 is ",ones)
print("number of 0 is ",zeros)

#calculate mean and SD of binomial distribution
#probability of occurence of 1 is p = 1/2 and occurence of 0 is q =1/2
#mean of Binomial distribution = np
#SD(standard deviation) of Binomial distribution = (npq)^1/2
#here n=50000 or length of array
n=len(myArray)
p=0.5
q=0.5
mean= n*p #expected mean of no of ones
sd = math.sqrt(n*p*q)
print("===============================")
print("mean of 1s in My Array: ",mean," sd(standard deviation): ",sd)
Lrange=int(round(mean-sd))
Rrange=int(round(mean+sd))
print("range: mean+-sd: ",Rrange," ",Lrange) #round off the range to nearest integer
#check if no of ones is within range
if(ones>= Lrange and ones<= Rrange):
output="Yes"
else:
output="No"

print("Actual number of ones is within the range mean+-sd ??? Ans is: ", output)

getting error line 11
for k in range(size):
^
IndentationError: expected an indented block please help

In: Computer Science

Given an array of n numbers, not necessarily in sorted order, we wish to find: (i)...

Given an array of n numbers, not necessarily in sorted order, we
wish to find: (i) the range (max - min) and (ii) the interquartile range (IQR) of the numbers.
IQR is defined as the difference between the number at the 25% percentile and the number at the
75% percentile. What is the exact number of comparisons needed for computing the range and
why? Using any algorithm from the chapters of the textbook covered so far as a subroutine, give
an efficient algorithm for computing IQR and analyze its time complexity (you do NOT need to
analyze the subroutine if you remember its time complexity). Show all steps.
(b) Given positive integers, x and n, as input, we wish to compute efficiently the number xn. What
is the size of the input and why? How many multiplications are required by the straightforward
algorithm that initializes an output variable to x and does output = output * x repeatedly until
output = xn. Is this a polynomial-time algorithm? Explain precisely and in detail.

In: Computer Science

I have gotten the answer?

I have gotten the answer?

In: Computer Science

Write a program that asks the user to enter the total precipitation for each of the...

Write a program that asks the user to enter the total precipitation for each of the twelve months of the year into a list. The program should calculate and display the total precipitation for the year, the average monthly precipitation, and the months with the highest and lowest precipitation amounts. FYI: precipitation is measured in inches.

Assume that precipitation amounts are floating-point numbers. You will need a list to store the precipitation amounts and another list to store the names of the months.

Here is a sample run:

Enter total precipitation for January: 3.44
Enter total precipitation for February: 3.01
Enter total precipitation for March: 4.32
Enter total precipitation for April: 4.12
Enter total precipitation for May: 4.37
Enter total precipitation for June: 4.60
Enter total precipitation for July: 5.05
Enter total precipitation for August: 3.98
Enter total precipitation for September: 4.53
Enter total precipitation for October: 3.82
Enter total precipitation for November: 3.94
Enter total precipitation for December: 4.23

Total precipitation: 49.41 inches.
Average precipitation: 4.12 inches.
July has the highest precipitation: 5.05 inches.
February has the lowest precipitation: 3.01 inches.

Notes:

  • The purpose of this problem is to practice using lists, list functions and methods, and the index system. Do not use loops or conditional branching
  • Please make sure to submit a well-written program. Good identifier names, useful comments, and spacing will be some of the criteria that will be used when grading this assignment.
  • This assignment can be and must be solved using only the materials that have been discussed in class. Do not look for alternative methods that have not been covered as part of this course.

PLEASE CODE IN PYTHON PROGRAMMING LANGUAGE

In: Computer Science

An investment project costs $10,000 and has annual cash flows of $3,000 for six years.   ...

An investment project costs $10,000 and has annual cash flows of $3,000 for six years.

  

a.

What is the discounted payback period if the discount rate is zero percent? (Enter 0 if the project never pays back. Do not round intermediate calculations and round your answer to 2 decimal places, e.g., 32.16.)

b. What is the discounted payback period if the discount rate is 6 percent? (Enter 0 if the project never pays back. Do not round intermediate calculations and round your answer to 2 decimal places, e.g., 32.16.)
c. What is the discounted payback period if the discount rate is 20 percent? (Enter 0 if the project never pays back. Do not round intermediate calculations and round your answer to 2 decimal places, e.g., 32.16.)

  

a. Discounted payback period years
b. Discounted payback period years
c Discounted payback period years

In: Finance

Explain network application architectures and protocols which are developed based on those architectures.

Explain network application architectures and protocols which are developed based on those architectures.

In: Computer Science

Please do in Java!! Stay on the Screen! Animation in video games is just like animation...

Please do in Java!!

Stay on the Screen! Animation in video games is just like animation in movies – it’s drawn image by image (called “frames”). Before the game can draw a frame, it needs to update the position of the objects based on their velocities (among other things). To do that is relatively simple: add the velocity to the position of the object each frame. For this program, imagine we want to track an object and detect if it goes off the left or right side of the screen (that is, it’s X position is less than 0 and greater than the width of the screen, say, 100).

Write a program that asks the user for the starting X and Y position of the object as well as the starting X and Y velocity, then prints out its position each frame until the object moves off of the screen. Design (pseudocode) and implement (source code) for this program.

Sample run 1: Enter the starting X position: 50

Enter the starting X velocity: 4.7

Enter the starting Y velocity: 2

X:50 Y:50

X:54.7 Y:52

X :59.4 Y:54

X:64.1 Y:56

X:68.8 Y:58

X:73.5 Y:60

X:78.2 Y:62

X:82.9 Y:64

X:87.6 Y:66

X:92.3 Y:68

X:97 Y:70

X:101.7 Y:72

In: Computer Science

1 (10 pts) Give a big-θ bound for the solutions of the following recurrence relations. Show...

1 (10 pts) Give a big-θ bound for the solutions of the following recurrence relations. Show work.

(a) T(n) = 8T(n/2) + n^3 + 100n

(b) T(n) = 5T(n/4) + 3n

(c) T(n) = 7T(n/3) + 100n^2

(d) T(n) = 3T(n/3) + 1000√ n

(e) T(n) = T(n − 1) + n^2

In: Computer Science

Exercise 5.5 PART A Copy or cut and paste program P5_2.cpp (located below) to a new...

Exercise 5.5

PART A

Copy or cut and paste program P5_2.cpp (located below) to a new program called ex55.cpp. Make PI a constant value. Compile and run the program for the following values:

r = 2 cm, h = 10 cm

The correct answer should be:
      The cross-section area of the cylinder is 3.89556 inch-sq
      The side area of the cylinder is 19.4778 inch-sqr

Did you get the correct answer? You didn't! Explain the reason for this logic error in your report. Now add the instruction that fixes the problem (yes, you need just one instruction) and save your file in ex55.cpp file.   HINT: r=r*0.3937; //converting r to inch

PART B

Modify the ex55.cpp to include a new function called total_area that computes the total surface area of a cylinder. The total surface area is the sum of the side area and cross-section area. Call your new program ex56.cpp.

For r=2 and h=10, the total area must be:  23.373383 inch-sqr.

Program P5_2.cpp:

// P 5_2.cpp This program illustrates the local and global variables and call-by-value.
// This program computes the side area and the cross section area of a cylinder
#include
#include
using namespace std;

//Let’s declare first any global constant, if any required

// This variable is defined globally, i.e. it is known to all functions in this program as PI

// To declare a global constant you must write it outside the main() function

const double PI = 3.14159;  

//Now we declare any programmer defined function

double cross_area(double r);                          // Function prototype for function cross_area
double side_area(double r, double h);            // Function prototype for function Side_area

// Start defining the main function

int main(void)
{
     double h, r; //variables local to the main function

      cout << "Enter the radius and the height of the cylinder in Cm ";
      cin >> r >> h;
      cout << endl;
      cout << "Before I do any computation or call any function, I want to let you know that \n";
      cout << "you have entered r = " << r << " and h = " << h << "." << endl;
      cout << "I am planning to use inch, thus in the first function, I will convert r, and " << endl;
      cout << "in the second one I will convert h \n";

      cout << "The cross section area of the cylinder is " << cross_area(r) << " inch-sqr" << endl;
      cout << "The side area of the cylinder is " << side_area(r,h) << " inch-sqr \n\n";

      return 0;
}

// Definition of all programmer defined functions

double cross_area(double r)
{
     //Cross section area includes the disks at the bottom and the top
      r = r * 0.3937; // converting r to inch
      return 2*PI*pow(r,2);
}

double side_area(double r, double h)
{
      double area; //variable local to side_area function
      h = h * 0.3937; // converting h to inch
      area = 2*PI*r*h;
      return area;
}

In: Computer Science

What are a few careers that are mostly dominated by men, and those that are dominated...

What are a few careers that are mostly dominated by men, and those that are dominated by women? Pick 1 career that is dominated by women, and 1 that is dominated by men, and explain how the opposite sex are treated in these careers (or other positions)? What does this suggest about the way gender structures human social relations?

In: Psychology

Write a program that computes the product of two fractions. The user provides 4 input which...

Write a program that computes the product of two fractions. The user provides 4 input which represent the numerator and the denominator of two fractions and prints the result of the operation. The program uses two functions. One called MultiplyNumerator(…) which calculates the product of the numerators of the fractions, and a second one called MultiplyDenom(…) which calculates the product of the denominator of the fractions. Call your program MultiplyFrac.cpp

In: Computer Science

Deposit function. Calculate the Balance - Deposit If the action is Deposit 'D’, use a deposit...

Deposit function.

Calculate the Balance - Deposit

If the action is Deposit 'D’, use a deposit function to add funds to the account

Deposit Input

userchoice = input ("What would you like to do?\n")
userchoice = 'B'
deposit_amount = 200

Deposit Output

What would you like to do?
How much would you like to deposit today?
Deposit was $200, current balance is $700.25
  1. Write a function called `deposit`.
  2. Request from the user the amount to be deposited. This value should be stored in a variable called `deposit_amount`. Use both the `input` and `float` methods in order to ensure the `deposit_amount` is a float value.
  3. Calculate a new account balance.
  4. The calculation for depositing funds into the account is `account_balance = account_balance + deposit_amount`.
  5. Print the new account balance.

#import sys #no need for this module

#account balance

account_balance = float(500.25)

#<--------functions go here-------------------->

#printbalance function

def printbalance():

print("Account balance: $%.2f" % account_balance)

#deposit function

def deposit():

#accessing account_balance variable which is outside the function

global account_balance

deposit_amount=float(input('How much would you like to deposit today?'))

account_balance+=deposit_amount

print('Deposit was $%.2f, current balance is $%.2f' % (deposit_amount,account_balance))

#withdraw function

def withdraw():

#accessing account_balance variable which is outside the function

global account_balance

withdrawal_amount=float(input('How much would you like to withdraw?'))

#withdrawing only if there is enough balance

if account_balance

print('withdrawal_amount is greater that your account balance of $%.2f' % account_balance)

else:

account_balance-=withdrawal_amount

print('Withdrawal amount was $%.2f, current balance is $%.2f' % (withdrawal_amount,account_balance))

userchoice=''

#looping until user enters Q or q

while userchoice.upper()!='Q':

userchoice = input ("What would you like to do? (D/W/B or Q)\n")

#converting to upper case to reduce comparisons

userchoice=userchoice.upper()

#performing operations based on choice

if userchoice=='D':

deposit()

elif userchoice=='W':

withdraw()

elif userchoice=='B':

printbalance()

elif userchoice=='Q':

print('Thank you for banking with us.')
  
else:

print('Not a valid choice')

In: Computer Science

What is the predominant intermolecular force in the liquid state of each of these compounds: ammonia...

What is the predominant intermolecular force in the liquid state of each of these compounds: ammonia (NH3), carbon tetrachloride (CCl4), and hydrogen sulfide (H2S)? Drag the appropriate items to their respective bins.

In: Chemistry

Java Programming In this assignment we are going to create our own programming language, and process...

Java Programming

In this assignment we are going to create our own programming language, and process it Java.

programming language has 6 commands

  1. enter
  2. add
  3. subtract
  4. multiply
  5. divide
  6. return

enter, add, subtract, multiply, divide all take 1 parameter (a double value).

return takes no parameters.

In: Computer Science

In the following code, what values could be read into a number to terminate the while...

In the following code, what values could be read into a number to terminate the while loop? PRINT "Enter a number: READ user input number ← user input WHILE (number < 1 or number > 10) PRINT "Enter another number: " READ user input number ← user input END WHILE

A) Numbers in the range 0 - 9

B) Numbers in the range 1 - 10

C) Numbers greater than 10

D) Numbers less than 1

In: Computer Science