Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. (a) (3 points) Write a program named powers.py that gets user input for two integers a and b, then computes and displays the value

image text in transcribed

3. (a) (3 points) Write a program named powers.py that gets user input for two integers a and b, then computes and displays the value of ab. You may assume that both a and b are non-negative. Sounds pretty easy, right? The catch here is that you cannot use Python's ** operator, or any other built-in way of finding powers. Instead, compute the result by repeatedly multiplying aaa for b times. Your code should work for any non-negative values of a and b, including zero. (Remember that anything to the 0th power is 1 .) Hint: Create a variable to store the result, and initialize it to 1. Then write a loop that repeats b times. Each iteration should multiply the result by a. (b) (3 points) Write a program named factorials.py that gets user input for an integer n, then computes and displays the value of n ! You may assume that n is non-negative. n ! (pronounced " n factorial") is defined as n(n1)(n2)1. For example, 5!=54321=120. Your program should work for any reasonably small non-negative value of n, including zero (note that 0 ! has a value of 1 ). Hint: This is very similar to the previous part. The only difference is that instead of multiplying by the same number every iteration, you're multiplying by something that changes. Use a variable to hold that changing value

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Technology And Management Computers And Information Processing Systems For Business

Authors: Robert C. Goldstein

1st Edition

0471887374, 978-0471887379

More Books

Students also viewed these Databases questions

Question

Give the efficiency for best, average, and worst cases of a BST

Answered: 1 week ago

Question

7. Where Do We Begin?

Answered: 1 week ago

Question

3. Are our bosses always right? If not, what should we do?

Answered: 1 week ago