Edit, Debug and Run the given Python script files
"""In distributed systems, it is a good idea to segregate threads into groups
if they are performing different tasks. Say, for instance, you have an
application that both listens for incoming stock price changes
and also tries to predict where that price will go. You could, for instance,
have two different thread groups here: one group listening for the changes
and the other performing the necessary calculations.
"""
import threading
import time
def myThread():
print("Thread {%} starting".format(threading.currentThread().getName()))
time.sleep(10)
print("Thread {} ending".format(threading.currentThread().getName()))
for i in range(4):
threadName = "Thread-" + str(i)
thread = threading.Thread(name=threadName, target=myThread)
thread.start()To fork a process is to create a second exact replica of the given process. i.e., When we fork something, we effectively clone it and then run it as a child process of the process that we just cloned from. The newly created process gets its own address space as well as an exact copy of the parent's data and the code executing within the parent process. The new cloned process receives its own unique (PID) Process identifier, and is independent of the parent process from which it was cloned.
Now, you’re required to write a Python script for forking existing processes by following this algorithm:
1.start by importing the os (operating systems) Python module.
2.then define two distinct functions, one called child() and another called parent(). Both the child() and the parent() just print out the process identifier(PID).
Ordered Matrix
Given a M x N matrix, write a program to print the matrix after ordering all the elements of the matrix in increasing order.Input
The first line of input will contain two space-separated integers, denoting the M and N.
The next M following lines will contain N space-separated integers, denoting the elements of each list.Output
The output should be M lines containing the ordered matrix.
Note: There is a space at the end of each line.Explanation
For example, if the given M is 3 and N is 3, read the inputs in the next three lines if the numbers given in the next three lines are the following.
1 20 3
30 10 2
5 11 15By ordering all the elements of the matrix in increasing order, the ordered matrix should be
1 2 3
5 10 11
15 20 30Sample Input 1
3 3
1 20 3
30 10 2
5 11 15
Sample Output 1
1 2 3
5 10 11
15 20 30
Sample Input 2
2 5
-50 20 3 25 -20
88 17 38 72 -10
Sample Output 2
-50 -20 -10 3 17
20 25 38 72 88
Given polynomial, write a program that prints poly in Cix^Pi + Ci-1x^Pi-1 + ..+ C1x + C0 format.
I/p
The 1st line contains a single integer N.
Next N lines contain 2 integers Pi, Ci separated with space, Pi denotes power and Ci denotes coef of Pi.
O/p
Print poly in format Cix^Pi + Ci-1x^Pi-1 + .. + C1x + C0, Pi's r powers in dec order, Ci is coeff, & C0 is constant. There will be space before & after + or - sign.
If coeff is 0, don't print term.
If term with highest degree is -ve, term should represent -Cix^Pi.
For term power is 1, represent it as C1x instead of C1x^1.
If the poly degree is 0 & constant term is also 0, then print 0 to represent the poly.
For term Cix^Pi, if coef of term Ci is 1, print x^Pi instead of 1x^Pi.
Exp:
If N = 4
For power 0, the coef is 5
1, the coef is 0
2, the coef is 10
3, the coef is 6.
Then poly n represents "6x^3 + 10x^2 + 5"Constraints
N <= 100
0 <= Pi < 1000
-1000 <= Ci <= 1000
Sample I/p
4
0 5
1 0
2 10
3 6
Sample O/p
6x^3 + 10x^2 + 5
First Prime Number
You are given N inputs. Write a program to print the first prime number in the given inputs.
Input
The first line of input is an integer N. The next N lines each contain an integer. Explanation
In the given example of
5 integers
1
10
4
3
2
The output should be
3.
Sample Input 1
5
1
10
4
3
2
Sample Output 1
3
Sample Input 2
4
2
3
5
7
Sample Output 2
2
Composite Numbers in the range
You are given two integers M, N as input. Write a program to print all the composite numbers present in the given range (including M and N).
Input
The first line of input is an integer M. The second line of input is an integer N.
Explanation
In the given example, the composite numbers present in the range between
2 to 9 are 4, 6, 8, 9.So, the output should be
4
6
8
9
Sample Input 1
2
9
Sample Output 1
4
6
8
9
Sample Input 2
1
4
Sample Output 2
4
Kth largest factor of N
Write a program to find the Kth largest factor of a number N.
Input
The first line is an integer N. The second line is an integer K.
Output
Print Kth largest factor of N. Print 1, If the number of factors of N is less than K.
Explanation
For
N = 12 and K = 3 The factors of 12 are 1, 2, 3, 4, 6, 12. The 3rd largest factor is 4.For
N = 12 and K = 7 The number of factors for 12 is only 6 and the given K is 7 (no of factors of N < K). Hence the output should be 1.
Sample Input 1
12
3
Sample Output 1
4
Sample Input 2
12
7
Sample Output 2
1
Replacing Characters of Sentence
You are given a string S. Write a program to replace each letter of the string with the next letter that comes in the English alphabet.
Note: Ensure that while replacing the letters, uppercase should be replaced with uppercase letters, and lowercase should be replaced with lowercase letters.
The first line of input is a string.
In the given example,
Hello World.
If we replace each letter with the letter that comes next in the English alphabet,
H becomes I, e becomes f and so on ... So, the output should be
Ifmmp Xpsme.
Sample Input 1
Hello World
Sample Output 1
Ifmmp Xpsme
Sample Input 2
Something is better than Nothing
Sample Output 2
Tpnfuijoh jt cfuufs uibo Opuijoh
Years, Weeks & Days
Given
The input contains single integer
Print space-separated integers
Given
N = 1329. The value can be written as 1329 = 3 years + 33 weeks + 3 days So the output should be
3 33 3.
using basic python