Question

The following are short Python calculations. Give the answer and the Python code for each. 1....

The following are short Python calculations. Give the answer and the Python code for each.

1. What is the sum of the numbers from 22:100 incrementing by 2? Do this in two ways: Use a while statement and a for loop to do the calculation. (Hint: make sure the numbers include 100)

2. What is the mean, standard deviation of the square root of the numbers from 3 to 5 incrementing by 0.1? Use the linspace function from the numpy package to do this. Find and read the help file for the function before writing your code

3. What is the sum of the numbers from 1 to 10 (by one) multiplied by the numbers from 11 to 30 (incrementing by two) respectively? (Hint: create two arrays and use the function numpy.dot to multiply them) 4. Generate a set of 1000 normal random numbers, with mean 0 and variance

4. Calculate the mean and standard deviation of the data series.

5. Generate an array containing a set of 100 normal random numbers, with mean 0 and standard deviation 1.5 (generate the random numbers with the seed=1. Google generate random normal number with seeds). Use a for loop and the if statement to create a new array which has the same value as the original array if the elements of the original array are positive and negative of the value if the elements are negative. Calculate and compare the mean the of two arrays

6. Repeat the task in 1.5 but use matrix Boolean indexing techniques

0 0
Add a comment Improve this question Transcribed image text
Answer #1

using for loop:

# this avariable to store the result, initially assigned to 0.
summation = 0

#using for sum over range 22 to 100(including) with division of 2.
for i in range(22,102,2):
summation = summation + i;

#print the sum.
print(summation)

using while :

# this avariable to store the result, initially assigned to 0.
summation = 0

# initially put i = 22
i = 22

#using while loop sum over range 22 to 100(including) with division of 2.
while(i <= 100):
  
summation = summation + i
  
# increamenting i with 2 steps.
i = i+2
  
#print the sum.
print(summation)

As per Chegg's policy, I am answering the first complete question.

thank you.

Add a comment
Know the answer?
Add Answer to:
The following are short Python calculations. Give the answer and the Python code for each. 1....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python What is the sum of the numbers from 1 to 10 (by one) multiplied by...

    Python What is the sum of the numbers from 1 to 10 (by one) multiplied by the numbers from 11 to 30 (incrementing by two) respectively? (Hint: create two arrays and use the function numpy.dot to multiply them)

  • code that I started: # THIS IS NEEDED TO USE ARRAYS IN PYTHON: from array import * # THIS IS NEEDED TO MAKE PLOTS IN PY...

    code that I started: # THIS IS NEEDED TO USE ARRAYS IN PYTHON: from array import * # THIS IS NEEDED TO MAKE PLOTS IN PYTHON: import matplotlib.pyplot as plt # IMPORT A ROUTINE FROM NUMPY USEFUL FOR CREATING AN # ARRAY FILLED WITH ZEROS from numpy import zeros # THIS COMMAND CREATES AN ARRAY OF ZEROS WITH DESIRED SHAPE: V=zeros([31,21]) newV=zeros([31,21]) # SET UP THE BOUNDARY VALUES: V=8 ON TOP OF BOX iy=20 for ix in range(0,31): V[ix,iy]=8.0 #...

  • PYTHON Generate a list of 50 random numbers ranging from 1 to 100 & use a...

    PYTHON Generate a list of 50 random numbers ranging from 1 to 100 & use a function that will remove duplicates from this list, compact it, and print the original and resulting lists. It MUST be well commented code with a description of the behavior.

  • need help with this python progam using numpy Create a 4x4 two dimensional array with numbers...

    need help with this python progam using numpy Create a 4x4 two dimensional array with numbers from 1 thru 16. show this then: Change the last element by dividing it in half. Show that the original array has changed. show this then: Set all values in row 2 to zero. Show the original array contains this change show this then: Set all values in column 1 to one. Shoe the original array contains this change. show this then: Display the...

  • Design a program using Python and using from flask Import flask that generates a lottery number...

    Design a program using Python and using from flask Import flask that generates a lottery number but in a website.. The program should have an Integer array with 9 elements. Write a loop that steps through the array, randomly generating a number in the range of 0 through 42 for each element. (Use the random function) Then write another loop that displays the contents of the array. Each number should be displayed as a list, the numbers should be generated...

  • write a small C program including the following C functions/subroutines. Your main routine should use these...

    write a small C program including the following C functions/subroutines. Your main routine should use these functions to generate a small-ish array of random values and show that the standard deviation lowers as the array is smoothed. • void random_array(double* array, int size, double scale); – load an array with random double values scaled by scale (random number generators generate double values between 0 and 1). Note: array should point to memory already allocated. • double sum(double* array, int size);...

  • Write a Code in Java or Python, for the following scenario(s): Consider three six-sided dice, and...

    Write a Code in Java or Python, for the following scenario(s): Consider three six-sided dice, and let random variable Y = the value of the face for each. The probability mass of function of Y is given by the following table: y 1 2 3 4 5 6 otherwise P(Y=y) 0.35 0.30 0.25 0.05 0.03 0.02 0 Roll the three dice and let random variable X = sum of the three faces. Repeat this experiment 50000 times. Find the simulated...

  • Plot a histogram 1 point Generate 10,000 normal random numbers with mean μ-0 and standard deviati...

    code in python 3 please Plot a histogram 1 point Generate 10,000 normal random numbers with mean μ-0 and standard deviation σ (the default). Plot them on a histogram with 25 bins Your submission should include a plot. Make sure to import matplotlib.pyplot as plt. Use plt.hist but not plt.show in your submission In order to obtain the histogram values for grading, please keep the form of the hist statement with the assignment below. Starter code (click to view) 1...

  • Please help code in c++ and use the answers you get from question 1 and 2...

    Please help code in c++ and use the answers you get from question 1 and 2 into the 3rd answer! Question 1 is first, question 2 is in the middle, question 3 is last Input Array (10 pts) te a function only (no main) that takes an array of doubles as a parameter as well as another integer rray. Create a for loop that asks the user to input any real number between-100 and r each element of the array....

  • please use python thanks will rate!! x + Run C Code Validate Implement the function step_random_walk_20(x_coords,...

    please use python thanks will rate!! x + Run C Code Validate Implement the function step_random_walk_20(x_coords, Y_coords) below, which should take two arrays of equal length containing the x-andy- coordinates for some number of particles. We'll use a very simple random walk algorithm • For each particle, choose a random angle between 0 and 2 • The particle moves by 1 unit of distance in the direction given by d.o. It is displaced by (Ax, Ay) (cos, sino). We'll do...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT