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

[M5_CSQ5] Construct an algorithm and write a python program python program to create


a regular expression to retrieve all words starting with vowels in each string. [CO2] [L2]


Test Cases are


case=1


case=2


input= An apple for a day input= Actions


keeps the doctor away louder than words.


I


output= An


output= Actions


apple


away


case=3


speak input= Everyone wants to


go to heaven, but nobody


wants to die.


output= Everyone



Part 2


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






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


Create a python program for physics and materials science. In physics, chemistry, and materials science, percolation refers to the movement and filtering of fluids through porous materials. (Wikipedia.org). Consider a simplified model below. Imagine, this is a filter or maybe some layers of stones such that when a certain amount of fluid is put on top, it will reach the bottom only if there is a direct passage. In this case, the blue squares serve as the porous materials or the holes where fluid may pass. Your task is to simulate this simple percolation by representing them in a 2-dimensional array. The input would be in a string, while the output would either be yes or no to indicate whether the fluid can pass through the filter or not.


Note: It should also work with these two inputs:

1. “1” -> Yes

2. “0” -> No


Examples:

Input: “1,0,0,0,0;0,1,0,0,0;0,1,0,0,0;0,0,1,0,0;0,0,0,1,0”

Output: Yes


Input: “0,0,0,1,0;0,1,0,0,0;0,1,0,0,0;0,0,1,0,0;0,0,0,1,0”

Output: No


Write a program to print the factorial of N

Write a python program to count number of digits in a given username. Show the first and last digits of the number, and summation of all the digits.

python program to decrypt the ciphertext into plain text. This scheme of cipher uses a text string (say, a word) as a key, which is then used for doing a number of shifts on the plaintext. For example, let’s assume the key is ‘point’. Each alphabet of the key is converted to its respective numeric value: In this case

p→16,o→15,i→9, n→14, and t→20.

Thus, the key is: 16 15 9 14 20

The sender and the receiver decide on a key. Say ‘point’ is the key. Numeric representation of this key is [16, 15, 9, 14, 20]

The sender wants to decrypt the message, say ‘pHBNVI’.arrange cipher test and numeric key to get the plain text as "Attack" (Toggle Case of each letter)

p H B N V I

p-16 o-14 i-9 n-14 t-20 p-16

a t t a c k

now left shifts each ciphertext by alphabet by the number written below it to create plain text as shown below

Input format

pHBNVZ

point

Output Format

[16, 15, 9, 14, 20, 16]

Attack


Write a python program to read n values in single line from user into a tuple. Using the values of tuple, display and count inversion. Count and Display the leader(s) from the tuple elements.

Inversion Count indicates – how far (or close) the tuple elements are far from being sorted in ascending order. If tuple is already sorted then inversion count is 0. If tuple is sorted in reverse order that inversion count is the maximum.

An element is leader if it is greater than all the elements to its right side. And the rightmost element is always a leader.

Input

5

2 4 5 1 3 #enter this element in single line

 

Output

Count Inversion (5) - [(2, 1), (4, 1), (4, 3), (5, 1), (5, 3)]

Leader (2) – [5, 3]

A number, a, is a power of b if it is divisible by b and a/b is a power of b. Write a function called is_power that takes parameters a and b and returns True if a is power of b.

LATEST TUTORIALS
APPROVED BY CLIENTS