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...

  • 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...

  • 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...

  • 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...

  • 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...

  • 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...

  • MEDIA INHERITANCE - C++ You will create an inheritance set of classes. Use proper rules for...

    MEDIA INHERITANCE - C++ You will create an inheritance set of classes. Use proper rules for data types, class definitions, and inheritance (check input/output of data below). You will create a super media class that will define a general form of media. A media properties will consist of the name and price. The media should be able to construct itself out of the arguments sent to it, virtually print both data fields labeled (price to two decimal places) and overload...

  • C++ Language Overview: Design an APP for a basketball team with a unique name. There should be at least 10 players. The member variables required include team member’s names, jersey number, position p...

    C++ Language Overview: Design an APP for a basketball team with a unique name. There should be at least 10 players. The member variables required include team member’s names, jersey number, position played, and at least 3 stats. Positions are small forward, power forward, center, shooting guard and point guard. 1. A.) Design a class with member variables and appropriate member functions Data should be stored in a read/write file consisting of team member’s names, jersey number, position played, and...

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