1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
snow_tiger [21]
2 years ago
5

This second python programming assignment, PA2, is about loop invariants. You will write a function eExp(left,right) that comput

es exponentials left ** right in a similar fashion as the egyptian_multiplication function computes products, as discussed in lecture 8: loop invariants.
eExp.txt contains some skeleton code. Download it and rename it eExp.py. Study egyptian multiplication in the lecture. The program logic in egyptian_multiplication, and thus the loop invariant is based on the fact that

a * b = if odd(a): b + (a//2)*(b*2)
else: (a//2)*(b*2)

and that p stepwise gathers the product.

For your exponentiation code, the program logic, and thus the loop invariant, is based on the fact that

n ** k = if odd(k): n * (n*n)**(k//2)
else (n*n)**(k//2)

and that e stepwise gathers the exponential.

Your job is to complete the code **INCLUDING** the correct assert statements to check the loop invariant, loop test and their combination, as indicated in the skeleton code. Leave the print statements in place. A correct implementation of eExp:

python3 eExp.py 2 11

produces

program: eExp.py 2 11
n: 2 k: 11 e: 1
n: 4 k: 5 e: 2
n: 16 k: 2 e: 8
n: 256 k: 1 e: 8
k: 0 e: 2048
2 ** 11 = 2048

exp.txt
mport sys

def eExp(left, right):
# precondition: left>0 AND right>0
if left <= 0 or right <= 0 : raise "eExp: invalid inputs!"
n=left; k=right; e=1 #e: the exponent
assert True # fill in the proper loop invariant
while (False) : # the loop test
assert True # fill in the proper loop test and loop invariant
print(" n:",n,"k:",k,"e:",e)
# body
assert True # fill in the proper loop invariant
print("k:",k,"e:",e)
assert True # fill in proper not(loop test) and loop invariant
return e

if __name__ == "__main__":
print("program:", sys.argv[0], sys.argv[1], sys.argv[2])
n = int(sys.argv[1])
k = int(sys.argv[2])
e = eExp(n,k)
print(n,"**",k,"=",e)
Computers and Technology
1 answer:
Andru [333]2 years ago
8 0
Describe a way you could model seafloor spreading I don’t know the answer I need points sorrynxjdidurkek dndirieo eemail eis and furious
You might be interested in
How do you use a iPad when it has a password ?
BaLLatris [955]
Take it to the Apple Store and they will help you or you can go on their site and press "Forgot Apple ID." If you choose the second option you have to enter the first and last name, and the email you used for the iCloud on the iPad. 
6 0
3 years ago
Read 2 more answers
Choose the statements that CORRECTLY describe a business organization.​
Kryger [21]

Answer:

An advantage to Corporations aI's a business organization is that they enjoy unlimited life and limited liability.

Explanation:

Unlimited life and limited liability are the major advantages of corporations.

Corporations have unlimited life unless all the shareholders decides to dissolve the corporation.

It has limited liability, it means that only the company assets will be sold in case of debt and investors are not liable to pay the debt.

3 0
3 years ago
The picture has the question on it
Bingel [31]

The answer is B. Row

4 0
2 years ago
Blender questions
Tamiku [17]
<span>14. A mesh represents a(n) _____ object if its faces enclose a positive and finite amount of space. (1 point)

odd

connected

simple

convex



15. Which of the following is the 3-D view port? (1 point)

the standard layout used for new files

the polygon viewing on the default screen

straight line segments connecting two vertices

a single static image in 3-D

The answer for number 1, should be:
SOLID
</span><span>A mesh represents a solid object if its faces enclose a positive and finite amount of space
</span>
The answer for the second question is:
a single static image in 3-D
4 0
2 years ago
Read 2 more answers
A homeowner uses a smart assistant to set the house alarm, get packages delivery updates, and set time on the outdoor lights. Wh
ch4aika [34]

The example where the alarm of the house set up, delivery updated should be provided, etc should represent the function example of the artificial intelligence.

The following information related to artificial intelligence is:

  • It refers to the human intelligence where the machines could be treated as humans and according to this, the actions should be mimic.
  • It should be used for any kind of machine where the traits should be associated along with the mind of the human-like for learning & problem-solving purpose.

Therefore we can conclude that The example where the alarm of the house set up, delivery updated should be provided, etc should represent the function example of the artificial intelligence.

Learn more about the machine here: brainly.com/question/2555822

3 0
3 years ago
Other questions:
  • You wish to enter your exam scores in a spreadsheet. Which function will help you find how each subject’s score relates to the o
    8·1 answer
  • How to move files and folders from desktop in w10?
    13·1 answer
  • Windows on the desktop are just one of many objects used in a graphical user interface (GUI)-- buttons, drop-down list boxes, po
    7·1 answer
  • How is the Internet Simulator similar to the Actual Internet? How is it different?
    7·1 answer
  • A queueing system has four crews with three members each. The number of "servers" is:
    5·2 answers
  • What is the output of the following code segment? int n = 0; for (int k = 0; k&lt; 2; k++) {n=n +2;} cout &lt;&lt; n; oo 0 1 O O
    8·1 answer
  • Abby wants to simply share a snapshot of her calendar with another user. Which option should she choose to achieve
    15·1 answer
  • Does anybody know how to unlock websites from school computer
    7·1 answer
  • Typically, a DVD has how many times more capacity than a CD?
    12·1 answer
  • JAVA -Develop a program that prompts the user to enter a series of 10 integers and then determines and displays the largest and
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!