Question

Python: Associate the average of the numbers from 1 to n (where n is a positive...

Python: Associate the average of the numbers from 1 to n (where n is a positive integer value) with the variable avg.

Homework Answers

Answer #1

Python code:

#accepting n from user
n=int(input("Enter n: "))
#finding average by summing up all numbers in the range 1 to n and dividing sum by n and assigning it to avg
avg=sum(range(1,n+1))/n
#printing the average
print("Average is",avg)


Screenshot:


Input and Output:

Know the answer?
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
Similar Questions
Write a python program to find the sum of the first n natural numbers, where the...
Write a python program to find the sum of the first n natural numbers, where the value of n is provided by the user. What is the sum of the first 200 numbers? Write a program that finds the average of a series of numbers entered by the user. As in the previous problem, the program will first ask the user how many numbers there are. Note: the average should always be a float. What is the average of 10.2,...
Write a python while loop that sums all the numbers from m to n, where “m”...
Write a python while loop that sums all the numbers from m to n, where “m” and “n” are both user given values.
Please implement a python program to solve the following problem, There are n integer numbers [0,1,...,n-1]...
Please implement a python program to solve the following problem, There are n integer numbers [0,1,...,n-1] forming a circle (increasing in the clockwise direction). Starting from 0 (as the 1st number), delete the m th number from the circle in the counterclockwise direction. After a number is deleted, the next starting position is the number adjacent to the deleted one going counterclockwise. Terminate the deletion when there are k numbers remaining in the circle. Please find the last k numbers...
python: find the maximum value from a sequence of positive numbers. you should print out the...
python: find the maximum value from a sequence of positive numbers. you should print out the maximum number from the sequence. output: Keep entering positive numbers. enter a number: enter a number: enter a number: enter a number: enter a number: largest number entered: ...
Prove 1/4 is not a limit point of 1/n where n is a positive integer.
Prove 1/4 is not a limit point of 1/n where n is a positive integer.
Covert the following Java program to a Python program: import java.util.Scanner; /** * Displays the average...
Covert the following Java program to a Python program: import java.util.Scanner; /** * Displays the average of a set of numbers */ public class AverageValue { public static void main(String[] args) { final int SENTINEL = 0; int newValue; int numValues = 0;                         int sumOfValues = 0; double avg; Scanner input = new Scanner(System.in); /* Get a set of numbers from user */ System.out.println("Calculate Average Program"); System.out.print("Enter a value (" + SENTINEL + " to quit): "); newValue =...
Write a script to display numbers from 1 to n, where n is an integer provided...
Write a script to display numbers from 1 to n, where n is an integer provided by users (if not, default to 10). Hint: use “read” command to accept user input. a) Display the source code in an editor (#4-9) b) Execute your script in the terminal, and display the command and the result (#4-10)
Create a python script that reads in an unknown number of positive numbers and negative numbers....
Create a python script that reads in an unknown number of positive numbers and negative numbers. These numbers are to be stored in two different collections. Once the user enters a zero value, the script will output all of the values in both collections, separately. Sample Usage/Output: Please enter a positive or negative number (enter a zero to end): 5 Please enter a positive or negative number (enter a zero to end): -7 Please enter a positive or negative number...
1. Let n be an odd positive integer. Consider a list of n consecutive integers. Show...
1. Let n be an odd positive integer. Consider a list of n consecutive integers. Show that the average is the middle number (that is the number in the middle of the list when they are arranged in an increasing order). What is the average when n is an even positive integer instead? 2. Let x1,x2,...,xn be a list of numbers, and let ¯ x be the average of the list.Which of the following statements must be true? There might...
Write a program that takes a positive integer argument N, and prints out the average, minimum,...
Write a program that takes a positive integer argument N, and prints out the average, minimum, and maximum (in that order) of N uniform random numbers that it generates. Note that all three statistics should be over the same sequence of N random numbers.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT