Questions: 5 831

Answers by our Experts: 5 728

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

the first output pattern of the code is

1:

[3spaces] ***

[2spaces] **

[1space] *


and

2: if input is [20 or 34 or any double digit like 87] then it should be 8+7 = 15 and 1+5 = 6 this type number reduction


Write a function named test_sqrt that prints a table like the following using a while loop, where


"dià" is the absolute value of the diàerence between my_sqrt(a) and math.sqrt(a).


a = 1 | my_sqrt(a) = 1 | math.sqrt(a) = 1.0 | diff = 0.0


a = 2 | my_sqrt(a) = 1.41421356237 | math.sqrt(a) = 1.41421356237 | diff =


2.22044604925e-16


a = 3 | my_sqrt(a) = 1.73205080757 | math.sqrt(a) = 1.73205080757 | diff =


0.0


a = 4 | my_sqrt(a) = 2.0 | math.sqrt(a) = 2.0 | diff = 0.0


a = 5 | my_sqrt(a) = 2.2360679775 | math.sqrt(a) = 2.2360679775 | diff = 0.0


a = 6 | my_sqrt(a) = 2.44948974278 | math.sqrt(a) = 2.44948974278 | diff =


0.0


a = 7 | my_sqrt(a) = 2.64575131106 | math.sqrt(a) = 2.64575131106 | diff =


0.0


a = 8 | my_sqrt(a) = 2.82842712475 | math.sqrt(a) = 2.82842712475 | diff =


4.4408920985e-16


a = 9 | my_sqrt(a) = 3.0 | math.sqrt(a) = 3.0 | diff = 0.0


Modify your program so that it outputs lines for a values from 1 to 25 instead of just 1 to 9


  1. Add a text file named poem.txt
  2. Search for a school appropriate short poem and copy and paste the contents into your poem.txt file. 

write a program which takes a number from the user if the number is not equal to 200, it asks the user to enter 4 more numbers and displays the result after subtracting the first 2 numbers and dividing the last 2 numbers.


2. Give at least three examples that show different features of string slices. Describe the feature illustrated by each example. Invent your own examples.


1. Consider the loop from Section 8.3 of your textbook.


prefixes = 'JKLMNOPQ'

suffix = 'ack'

for letter in prefixes:

   print(letter + suffix)

Put this code into a Python script and run it. Notice that it prints the names "Oack" and "Qack".

Modify the program so that it prints "Ouack" and "Quack" but leaves the other names the same.

Include the modified Python code and the output in your submission.


Write a function named test_sqrt that prints a table like the following using a while loop, where "diff" is the absolute value of the difference between my_sqrt(a) and math.sqrt(a). 

a = 1 | my_sqrt(a) = 1 | math.sqrt(a) = 1.0 | diff = 0.0

a = 2 | my_sqrt(a) = 1.41421356237 | math.sqrt(a) = 1.41421356237 | diff = 2.22044604925e-16

a = 3 | my_sqrt(a) = 1.73205080757 | math.sqrt(a) = 1.73205080757 | diff = 0.0

a = 4 | my_sqrt(a) = 2.0 | math.sqrt(a) = 2.0 | diff = 0.0

a = 5 | my_sqrt(a) = 2.2360679775 | math.sqrt(a) = 2.2360679775 | diff = 0.0

a = 6 | my_sqrt(a) = 2.44948974278 | math.sqrt(a) = 2.44948974278 | diff = 0.0

a = 7 | my_sqrt(a) = 2.64575131106 | math.sqrt(a) = 2.64575131106 | diff = 0.0

a = 8 | my_sqrt(a) = 2.82842712475 | math.sqrt(a) = 2.82842712475 | diff = 4.4408920985e-16

a = 9 | my_sqrt(a) = 3.0 | math.sqrt(a) = 3.0 | diff = 0.0 

Modify your program so that it outputs lines for a values from 1 to 25 instead of just 1 to 9.



Encapsulate the following Python code from Section 7.5 in a function named my_sqrt that takes a as a parameter, chooses a starting value for x, and returns an estimate of the square root of a. 

while True:

   y = (x + a/x) / 2.0

   if y == x:

     break

   x = y 


 Each of the following Python functions is supposed to check whether its argument has any lowercase letters.


For each function, describe what it actually does when called with a string argument. If it does not correctly check for lowercase letters, give an example argument that produces incorrect results, and describe why the result is incorrect.

# 1

def any_lowercase1(s):

   for c in s:

     if c.islower():

        return True

     else:

        return False


# 2

def any_lowercase2(s):

   for c in s:

     if 'c'.islower():

        return 'True'

     else:

        return 'False'


# 3

def any_lowercase3(s):

   for c in s:

     flag = c.islower()

   return flag


# 4

def any_lowercase4(s):

   flag = False

   for c in s:

     flag = flag or c.islower()

   return flag


# 5

def any_lowercase5(s):

   for c in s:

     if not c.islower():

        return False

   return True


<i title="Previous: Reading Assignment"></i>


1. Demonstrate use of Object Oriented Programming (OOP) principles, data structures and file

handling operations to carry out the following tasks:

a) Define a class named Person, with child classes named Daughter and Son who also have

have derived classes named GrandSon and GrandDaughter respectively. All child

classes have derived genetic features and skills from Person. Create 5 methods for

getting and setting genetic features, setting and getting skills and demonstrate the concept

of polymorphism.

b) Modify the answer in a) and show how the person features are captured in a file called

person.txt. Also create another method to read from the file person.csv and store the data

in a list called persondata. Clearly show how exceptions are handled in your program.


LATEST TUTORIALS
APPROVED BY CLIENTS