Answered>Order 22973

Write a 13 page essay on Programming using Python.

Download file to see previous pages…

7.import turtle

import math

turtle.forward(50)

turtle.right(90)

turtle.forward(50)

turtle.right(90)

turtle.forward(50)

turtle.right(90)

turtle.forward(50)

turtle.right(90+45)

turtle.forward (math.sqrt(2*50*50))

turtle.right(90+45)

turtle.forward(50)

turtle.right(90+45)

turtle.forward (math.sqrt(2*50*50))

turtle.left (45)

turtle.left(45)

turtle.forward (math.sqrt(25*50))

turtle.left(90)

turtle.forward (math.sqrt(25*50))

8.save

#!./bday.py

Answers for Section 2.11, Exercises

1. From the given statements (Print 12, print “12”), both the statements would print the value 12, The first statement (print 12) can only print the literal value 12 since variable names cannot begin with a number. However, (print a, print “a”) statements would make a difference because ‘print a’ would print the value of able named ‘a’.

2. The literals from the given piece of code are given below, in each line separately.

1

dog

, went to mow a meadow.

man

and his

,

,

and his

3. The output of the given code is exactly as below :

1 man and his dog , went to mow a meadow. 3 man , 2 man , 1 man and his dog , went to mow a meadow.

4. The Python Interpreter would return the output “8” for the input 4+4/2+2 .

5.print (2)

print (5)

print (6)

6. The correct program to convert from dollars to British pounds is given below :

dollars = 10

conv = 1.75

pounds = dollars / conv

print dollars, “USD is “, pounds,”GBP.”

7. The below code for example, uses the a modified convert function to convert US Dollars to Indian Rupees.

def convert (USD, conv, target_c):

result = USD * conv

print USD,”dollars is “,result,target_c

convert (50,…

The best looking spirals however, are those with only a small change in the value after every loop of the square, small values will generate the spiral with closely packed loops.

1. From the given statements (Print 12, print “12”), both the statements would print the value 12, The first statement (print 12) can only print the literal value 12 since variable names cannot begin with a number. However, (print a, print “a”) statements would make a difference because ‘print a’ would print the value of able named ‘a’.

The way of terminating the recursive function when the value of ‘pow’ reaches zero, is to use an ‘if’ condition to evaluate if the value of ‘pow’ has in fact reached below zero, thereby returning the value 1.

3. The power function from Section 5.3, uses a more efficient means of evaluating a number’s exponent by using a more efficient mathematical expression, i.e the function recurses differently depending on whether the given number is even or odd by performing a modulo operation. By this method, the number of multiplications are reduced and thereby, is more efficient due to less memory usage and consumption. On the contrary, the Power function from Section 5.1 simply calls itself with a standard multiplication operator and thereby involves more multiplications and memory usage as a result of which, efficiency is the least.

 
"Not answered?"
Get the Answer