Question: Python programs 1. Write a program that asks the user to enter two words. The program then prints out both words on one line. The

Python programs

1. Write a program that asks the user to enter two words. The program then prints out both words on one line. The words will be separated by enough dots so that the total line length is 30: Enter first word: turtle Enter second word 153 turtle....................153 This could be used as part of an index for a book. To print out the dots, use System.out.print(".") inside a loop body.

2. Write a program that adds up integers that the user enters. First the programs asks how many numbers will be added up. Then the program prompts the user for each number. Finally it prints the sum. How many integers will be added: 5 Enter an integer: 3 Enter an integer: 4 Enter an integer: -4 Enter an integer: -3 Enter an integer: 7 The sum is 7 Be careful not to add the number of integers (in the example, 5) into the sum

3. Write a program that computes the standard deviation of a set of floating point numbers that the user enters. First the user will say how many numbers N are to follow. Then the program will ask for and read in each floating point number. Finally it will write out the standard deviation. The standard deviation of a set of numbers Xi is: SD = Math.sqrt( avgSquare - avg 2 ) Here, avg is the average of the N numbers, and avg 2 is its square. avgSquare is the average of Xi * Xi. In other words, this is the average of the squared value of each floating point number. For example, if N = 4, say the numbers were: Xi Xi * Xi 2.0 4.0 3.0 9.0 1.0 1.0 2.0 4.0 ----- ------ sum 8.0 18.0 then avg = 8.0/4 = 2.0 avg 2 = 4.0 avgSquare = 18.0/4 = 4.5 SD = Math.sqrt( 4.5 - 4.0 ) = Math.sqrt( .5 ) = 0.7071067812 To do this you will need to do several things inside the loop body for each floating point value as it comes in: add it to a sum, square it and add it to a sum of squares. Then after the loop is finished apply the formula

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!