Question

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, 1.3, 5.4, 2.2, 5.5, and 14.2?

Answer #1

1. The Python program to find the sum of first n natural numbers with a sample output is provided below :

**CODE
:**

num = int(input("Enter the value of n: "))

item = num

sum = 0

if num <= 0:

print("Enter a whole positive number!")

else:

while num > 0:

sum = sum + num

num = num - 1;

print("Sum of first", item, "natural numbers is: ", sum)

**SAMPLE
OUTPUT :**

2. The Python program that finds the average of a series of numbers entered by the user is provided below :

**CODE
:**

n=int(input("Enter the total number you want to enter:"))

sum=0

for i in range(n):

x=float(input("Enter the number:"))

sum=sum+x

avg=sum/n

print("Average=",avg)

**SAMPLE
OUTPUT :**

If you have any doubt/query regarding the above solution, then let me know in the comment. If the solution helps, kindly give an upVote to the answer.

Step 1: Write a Java program that finds the sum of 10 numbers
entered by the user.
Step 2: Modify the previous program so that it asks the user how
many numbers they have, inputs that many numbers, and finally
outputs the average of their numbers. The messages to the user
should be clear throughout.

Write a Python program to find the sum of the binary numbers in
list L, where the binary numbers do not have the quote marks
necessary for the int() function. For example, if L = [101, 11,
1010] then the sum is 5 + 3 + 10 = 18. What is the sum when L is L
= [10100, 101000, 100000, 1011111, 1000, 1010111, 1010010, 11001,
101100, 10111, 11011, 1011010, 11101, 10, 110011, 1001111, 110010,
101100, 100001, 111001]

Write a Python program which calculates the average of the
numbers entered by the user through the keyboard. Use an
interactive loop and ask the user at each iteration if he/she wants
to enter more numbers. At the end dispay the average on the screen.
Using built-in library functions for finding average is not
allowed.
Sample output of the program:
Enter a number > 23
More numbers (yes or no)? y
Enter a number > 4
Do you have more...

Write a Python program using while loop that finds and prints
the sum of this geometric series.
1 + 2 +4 +8 + … + 1024

write a java program to find the sum of natural numbers from 1
to 1000 inclusive (using for loop)
sample output:
sum=500500

1) In Python Use a while loop to ask the user to enter a series
of alphabets. The loop terminates when the user presses enter. Once
the loop terminates, display the number of vowels and consonants
entered by the user.
Hint: keep a running count of the number of characters entered
by the user. Keep a running count of the number of vowels.
Total number of consonants = total number of characters - total
number of vowels.
Assume that the...

Python code
Write a complete program with for loop which calculates the sum
of the numbers from 1 to 100

Write a PYTHON program that displays a weekly payroll report. A
loop in the program should ask the user for the employee number,
gross pay, state tax, federal tax, and FICA withholdings. The loop
will terminate when 0 is entered for the employee number. After the
data is entered, the program should display totals for gross pay,
state tax, federal tax, FICA withholdings, and net pay. Input
Validation: ▪ Do not accept negative numbers for any of the items
entered....

Write a python program that does the
following:
Prompts the user for three numbers in one request.
Be sure to specify the “delimiter” by which a user enters those
three numbers.
Divides the first number by the second number and add that result
to the third number.
Prints output that shows in one line the formula applied and the
result of the calculation.
Validate input by:
• Checking the user
entered 3 values
• Appropriately
checking for the following errors:...

PYTHON- write a program that accepts a param (num) that will
determine how many numbers will be in the output. every number
after the first is the product of the prev 2 numbers, we will
always start with [5,2] . return output (list)
example. the user will insert 6 as the num. we start with [5,2]
and the output will be [5,2,10,20,200,4000]

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 35 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 3 hours ago

asked 3 hours ago

asked 3 hours ago

asked 3 hours ago

asked 3 hours ago

asked 3 hours ago

asked 4 hours ago