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
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: ...
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 =...
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.
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 python code that will ask the user to enter an integer number n. Construct...
Write a python code that will ask the user to enter an integer number n. Construct a recursive function that prints numbers 1 to n in the form “11223344..nn”.
Show that the set of all rational numbers of the form n/5, where n is an...
Show that the set of all rational numbers of the form n/5, where n is an integer, is countable?
Show that the set of all rational numbers of the form n/5, where n is an...
Show that the set of all rational numbers of the form n/5, where n is an integer, is countable?
In Python language: Create a function that takes as input two numbers, m and n, m<n,...
In Python language: Create a function that takes as input two numbers, m and n, m<n, and returns an m×n list-of-list-of-numbers. Each element of the outer list will be a list of consecutive integers, beginning with 1 and ending with n−1. If you're feeling bold, try to use list comprehension.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT