
Concept explainers
Write a program that performs the following:
1) request an integer input by the user
2) display the value of 1 + 1/2 + 1/3 + ... + 1/n to five decimal places
3) display the average to five decimal places
Input text can be any content. Just make sure to precisely match the output format below.
Write your entire program in the Answer area provided below (must include comments if using code is not covered in the course).
Example Output
Enter an integer: 100
The sum 1 + 1/2 + 1/3 + ... + 1/n (n = 100) is 5.18738.
The average is 0.05187.
PYthon

#declare sumOfNumbers and averageOfNumbers
sumOfNumbers=0
averageOfNumbers=0
#input the value of n
n=int(input("Enter a number: "));
#iterate the loop from 1 to n inclusive
for i in range(1,n+1):
sumOfNumbers+= 1/float(i) #either of value to be converted to float
print "%.5f"%sumOfNumbers #displaying sum with precision 5
print "%.5f"%(float(sumOfNumbers)/n)#displaying average precision with 5
Step by stepSolved in 2 steps with 1 images

- 1) Request a fruit from the console.2) Print out the fruit in the format shown in the example output. Input text can be any content. Just make sure to precisely match the output format below.Write your code in the ANSWER area provided below (must include comments if using code is not covered in the course). Example OutputEnter a fruit: appleApple is delicious.arrow_forward3. Write a code that accepts any number and compute the sum from 1 to the Nth number. If the user input 5. So the program will compute the sum from 1 to 5. If the user input 10, the program will compute the sum from 1 to 10.arrow_forward1) Use a loop to request a user input from the console. 2) The loop should end when a string, '574', is entered. Input text can be any content. Just make sure to precisely match the output format below.Write your code in the ANSWER area provided below (must include comments if using code is not covered in the course). Example OutputEnter anything (or enter 574 to stop): 0Enter anything (or enter 574 to stop): 5.5Enter anything (or enter 574 to stop): -123Enter anything (or enter 574 to stop): a+bEnter anything (or enter 574 to stop): LOOPEnter anything (or enter 574 to stop): 574arrow_forward
- Please do it on Visual Studios using Python. (Use version Python3)arrow_forwardPython Programmingarrow_forward1) Request a float number user input, price, from the console.2) Print "Price Matches" if the variable price is equal to a float number, 99.99.3) Otherwise print "Price Not Found". Input text can be any content. Just make sure to precisely match the output format below.Write your code in the ANSWER area provided below (must include comments if using code is not covered in the course).Example Output 1Enter the search price: 99Price Not Found Example Output 2Enter the search price: 99.99Price Matchesarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





