Question

IN PYTHON Print out a table of powers. Use a for loop that goes from 101 to 112 inclusive. Print out r, r squared, r cub...

IN PYTHON

Print out a table of powers. Use a for loop that goes from 101 to 112 inclusive. Print out r, r squared, r cubed, square root of r, and cube root of r. Use two decimal places for the roots, and zero decimal places for the squares and cubes, and 2 decimal places for the averages. Use commas in numbers 1000 and above. After the loop, print out the average of the r squared and r cubed. Use columns for your data. Print column headings above your loop.

Also print the data to a file. Attach the file to your submission or attach a screen shot of th open file to the top of your Word document. Use a txt extension for your file so I can open it in notepad.

So, you will have output to the screen as usual, and also to the file. You can attach as many files as you need to an assignment, just don't click Submit until you have all the files attached.

I would get the output working to the screen first, then add a 2nd print line to print to the file. Files are in the chapter on loops/repetition.

^ will not raise to a power. Use the pow function, sqrt, cbrt, etc. depending on your language.

Note: pow(8,(1.0/3.0) will also take a cube root.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

print%5s% 10s%15s%15s%10s % (Num, Squared, Cubed, squareRoot, cubeRoot)) Python 3.6.1 (default, Dec 2015, 13:05:11

print('%5s%10s%15s%15s%10s' % ('Num', 'Squared', 'Cubed', 'SquareRoot', 'CubeRoot'))

totalSq = 0
totalCu = 0
count = 0
for num in range(101, 113):
        s = num * num
        c = s * num
        sr = num ** 0.5
        cr = num ** (1/3)
        print("{:5,d}{:10,d}{:15,d}{:15,.2f}{:10,.2f}".format(num, s, c, sr, cr))

        totalSq += s
        totalCu += c
        count += 1

print()
print('Squared value avg: {:,.2f}'.format(totalSq/count))
print('Cube value avg: {:,.2f}'.format(totalCu/count))

please upvote. Thanks!
Add a comment
Know the answer?
Add Answer to:
IN PYTHON Print out a table of powers. Use a for loop that goes from 101 to 112 inclusive. Print out r, r squared, r cub...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Calculate and print the area and volume of a cone inside a While  loop that goes from...

    Calculate and print the area and volume of a cone inside a While  loop that goes from 1 to 20 with a step of .5. (the step is 1/2 or Point 5, so you go 10, 10.5,11, 11.5) Note: Your loop variable will need to be a double data type Use two decimal places on all numbers that are double data type. This will be a table with 3 columns. Use r as the loop counter and as the radius. Let...

  • Your mission in this programming assignment is to create a Python program that will take an...

    Your mission in this programming assignment is to create a Python program that will take an input file, determine if the contents of the file contain email addresses and/or phone numbers, create an output file with any found email addresses and phone numbers, and then create an archive with the output file as its contents.   Tasks Your program is to accomplish the following: ‐ Welcome the user to the program ‐ Prompt for and get an input filename, a .txt...

  • Piggy back on the programming project one you completed in module 3. You will use some...

    Piggy back on the programming project one you completed in module 3. You will use some of those concepts here again. We will be building this project inside out, start individual quiz and use a for loop to repeat it three times for three students. In this program you will be required to write a python program that generates math quizzes for students in second grade. Your program should do the following Ask the student for their name Provide 3...

  • I'm a bit confused on how to get this program to run right. Here are the...

    I'm a bit confused on how to get this program to run right. Here are the directions: Part 1: Write a Python function called reduceWhitespace that is given a string line and returns the line with all extra whitespace characters between the words removed. For example, ‘This line has extra space characters ‘  ‘This line has extra space characters’ Function name: reduceWhitespace Number of parameters: one string line Return value: one string line The main file should handle the...

  • IN PYTHON PLEASE...... Process bowlers and their 3 bowling scores. Use my data file below: bowlers2.txt...

    IN PYTHON PLEASE...... Process bowlers and their 3 bowling scores. Use my data file below: bowlers2.txt ( Showed below) And you can also use a while loop to read your file if you prefer. How to average down an array, which you don’t have to do. In this case that would be the game 1 average for all bowlers for example. Find the low average and high average. Start with read the data into arrays/lists and printed out the arrays/lists...

  • in Python Objective: Practice Displaying Output with print Function, Comments, Variable, Reading Input from the Keyboard,...

    in Python Objective: Practice Displaying Output with print Function, Comments, Variable, Reading Input from the Keyboard, format output, if statement, if-else statement, loop structure. import, functions, file handling. and string methods. Lab Description: You are given a file containing protein sequences with the task of finding motifs. Motifs are certain patterns of amino acids that appear many times in protein sequences that act as indictors or markers for special regions, genes, mutations, etc. An example of what this file will...

  • I am confused on how to read valid lines from the input file. I am also...

    I am confused on how to read valid lines from the input file. I am also confused on how to count the averages from these valid input lines to keep running the total from these valid lines. If you could show an example of an input and output file that would be amazing as well. Purpose        Learn how to use Java input/output. Due Date       Per the Course at a Glance. Can be resubmitted. Submissions           In this order: printed copy of...

  • C++ requirements The store number must be of type unsigned int. The sales value must be...

    C++ requirements The store number must be of type unsigned int. The sales value must be of of type long long int. Your program must properly check for end of file. See the section Reading in files below and also see your Gaddis text book for details on reading in file and checking for end of file. Your program must properly open and close all files. Failure to follow the C++ requirements could reduce the points received from passing the...

  • Newmultiply.Java // NewMultiply.java - This program prints the numbers 0 through 10 along // with these...

    Newmultiply.Java // NewMultiply.java - This program prints the numbers 0 through 10 along // with these values multiplied by 2 and by 10. // Input: None. // Output: Prints the numbers 0 through 10 along with their values multiplied by 2 and by 10. public class NewMultiply {    public static void main(String args[])    {               String head1 = "Number: ";        String head2 = "Multiplied by 2: ";        String head3 = "Multiplied...

  • please help!! the first photo is to answeer the 4 questions! i really just need help...

    please help!! the first photo is to answeer the 4 questions! i really just need help on question 11 and 12 QUESTION 9 Instructions A link to the data marathon is included in this section. You will use JMP to answer questions 9. 13. Each question includes the steps needed in JMP. In the following paragraph, you will find the steps to save graphs that you will need. marathon.txt Before loading the file into JMP, you will need to do...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT