Write a program to count Vowels and Consonants in string.
Input
The input will be a single line containing a string s.
Output
The first line of output should contain no of Vowels in the given string
The second line of output should contain no of Consonants in the given string
Explanation
For example, if the given string is "Good Morning"
Vowels in the string "Good Morning" are "o, i" and their count is 4.
Remaining characters in the string are consonants their count is 7.
The First line of output is 4\nThe second line of output is 7.
Sample Input 1
Good Morning
Sample Output 1
4
7
Sample Input 2
welcome
Sample Output 2
3
4Write a program to count even and odd numbers in given range [M, N]. Both M, N are inclusive in [M, N].
Input
The first line of the input will be an integer(M).
The Second line of the input will be an integer(N).
Output
The first line of output should be a number of odds count.
The second line of output should be a number of even counts.
Explanation
For example, if the given range is 2 to 11
odds numbers in the range are 3, 5, 7, 9, 11 then count is 5.
even numbers in the range are 2, 4, 6, 8, 10 then count is 5.
Sample Input 1
2
11
Sample Output 1
5
5
Sample Input 2
-5
7
Sample Output 2
7
6Matrix Rotations
You are given a square matrix A of dimensions NxN. You need to apply the below given 3 operations on the matrix A.
Rotation: It is represented as R S where S is an integer in {90, 180, 270, 360, 450, ...} which denotes the number of degrees to rotate. You need to rotate the matrix A by angle S in the clockwise direction. The angle of rotation(S) will always be in multiples of 90 degrees.
Update: It is represented as U X Y Z. In initial matrix A (as given in input), you need to update the element at row index X and column index Y with value Z.
After the update, all the previous rotation operations have to be applied to the updated initial matrix.
Querying: It is represented as Q K L. You need to print the value at row index K and column index L of the matrix A.
Input
The first line contains a single integer N.
Next N lines contain N space-separated integers Aij (i - index of the row, j - index of the column).
Next lines contain various operations on the array. Each operation on each line (Beginning either with R, U or Q).
-1 will represent the end of input.
Output
For each Query operation print the element present at row index K and colum index L of the matrix in its current state.
Explanation
For Input:
2
1 2
3 4
R 90
Q 0 0
Q 0 1
R 90
Q 0 0
U 0 0 6
Q 1 1
-1
Initial Matrix
1 2
3 4
For R 90, clockwise rotation by 90 degrees, the matrix will become
3 1
4 2
For Q 0 0, print the element at row index 0 and column index 0 of A, which is 3.
For Q 0 1, print the element at row index 0 and column index 1 of A, which is 1.
Again for R 90, clockwise rotation by 90 degrees, the matrix will become
4 3
2 1
For Q 0 0, print the element at row index 0 and column index 0 of A, which is 4.
For U 0 0 6, update the value at row index 0 and column index 1 in the initial matrix to 6. So the updated matrix will be,
6 2
3 4
After updating, we need to rotate the matrix by sum of all rotation angles applied till now(i.e. R 90 and R 90 => 90 + 90 => 180 degrees in clockwise direction).
After rotation the matrix will now become
4 3
2 6
Next for Q 1 1, print the element at row index 1 and column index 1 of A, which is 6.
output
3
1
4
6
Sample Input 1
2
1 2
3 4
R 90
Q 0 0
Q 0 1
R 90
Q 0 0
U 0 0 6
Q 1 1
-1
Sample Output 1
3
1
4
6
Sample Input 2
2
5 6
7 8
R 90
Q 0 1
R 270
Q 1 1
R 180
U 0 0 4
Q 0 0
-1
Sample Output 2
5
8
8
Temperature Conversion
You are given the temperature T of an object in one of Celsius, Fahrenheit, and Kelvin scales.
Write a program to print T in all scales viz Celsius, Fahrenheit, and Kelvin.
Formula to convert from Fahrenheit F to Celsius C is C = (F - 32) * 5 / 9.
Formula to convert from Kelvin K to Celsius C is C = K - 273.
Here "C", "F", "K" represent that the temperature scale is in Celsius, Fahrenheit and Kelvin scales respectively.
The input contains the temperature (a number) and the unit of the temperature scale (C, F, K) without any space.
The output contains temperature in Celsius, Fahrenheit and Kelvin scales in each line in the format similar to input and the value of the temperature is rounded to 2 decimal places.Input
The first line of the input contain a temperature Value in one of Celsius, Fahrenheit, and Kelvin scales.Output
The first line of output should contain the Celsius value and the unit of the Celsius without any space.
The second line of output should contain the Fahrenheit value and the unit of the Fahrenheit without any space.
The third line of output should contain the Kelvin value and the unit of the Kelvin without any space.Explanation
For example, if the given temperature Value is 25C then Celsius value is 25.0C, Fahrenheit value is 77.0F, and Kelvin value is 298.0K.
Sample Input 1
25C
Sample Output 1
25.0C
77.0F
298.0K
Sample Input 2
37.5F
Sample Output 2
3.06C
37.5F
276.06K
You are given the temperature T of an object in one of Celsius, Fahrenheit, and Kelvin scales.
Write a program to print T in all scales viz Celsius, Fahrenheit, and Kelvin.
Formula to convert from Fahrenheit F to Celsius C is C = (F - 32) * 5 / 9.
Formula to convert from Kelvin K to Celsius C is C = K - 273.
Here "C", "F", "K" represent that the temperature scale is in Celsius, Fahrenheit and Kelvin scales respectively.
The input contains the temperature (a number) and the unit of the temperature scale (C, F, K) without any space.
The output contains temperature in Celsius, Fahrenheit and Kelvin scales in each line in the format similar to input and the value of the temperature is rounded to 2 decimal places.
Input
The first line of the input contain a temperature Value in one of Celsius, Fahrenheit, and Kelvin scales.
Output
The first line of output should contain the Celsius value and the unit of the Celsius without any space.
The second line of output should contain the Fahrenheit value and the unit of the Fahrenheit without any space.
The third line of output should contain the Kelvin value and the unit of the Kelvin without any space.
Explanation
For example, if the given temperature Value is 25C then Celsius value is 25.0C, Fahrenheit value is 77.0F, and Kelvin value is 298.0K.
Sample Input 1
25C
Sample Output 1
25.0C
77.0F
298.0K
Sample Input 2
37.5F
Sample Output 2
3.06C
37.5F
276.06KTic-Tac-Toe game
Abhinav and Anjali are playing the Tic-Tac-Toe game. Tic-Tac-Toe is a game played on a grid that's three squares by three squares. Abhinav is O, and Anjali is X. Players take turns putting their marks in empty squares. The first player to get 3 of her marks in a diagonal or horizontal, or vertical row is the winner. When all nine squares are complete, the game is over. If no player has three marks in a row, the game ends in a tie. Write a program to decide the winner in the Tic-Tac-Toe game.
Input
The input will be three lines contain O's and X's separated by space.
Output
The output should be a single line containing either "Abhinav Wins" or "Anjali Wins" or "Tie".
Explanation
For example, if the input is
O X O
O X X
O O X
as three of O's are in vertical row print "Abhinav Wins".
Sample Input 1
O X O
O X X
O O X
Sample Output 1
Abhinav Wins
Sample Input 2
O O X
X X O
X O O
Sample Output 2
Anjali Wins
The minimal requirements of your program are:
• Present the user with a menu, wherein s/he may decide:
◦ Which dishes to make (with up to four dishes, this means up to 4 threads)
◦ The number of each dish to prepare (ideally a separate number for each dish)
◦ How often should progress be reported? (Explained further below)
• Start a thread for each dish
◦ Each type should be implemented into its own thread, since it has its own lock requirements
◦ Each dish tries to report upon completing one (subject to above/below)
◦ Each dish type always reports when completed its iterations
▪ Obviously there's no reporting if none are being made at all
• The program then reports on the total number of dishes produced
• If this isn't obvious, increasing the tally and output are also a 'resource'
Write your threads immensely clearly, and comment it.
• Comment usefully. Don't add nonsense like identifying that a loop “loops”, or that .lock() “locks”
• Also, proper indentation, please?
Obviously, you'll have several .java files for this (if using Java).
Pseudo Code:
import threading
todo=2000000
confirmed=0
lock=threading.Semaphore() #We had some interesting options here
def worker(id):
global todo, confirmed
print("\t"+str(id)+" thinking...")
while True:
#We could do extra work here
lock.acquire() #Either acquire
the lock, or block until it's ready
if todo==0:
break
todo-=1
confirmed+=1
lock.release()
#We could also do work here
print("\t"+str(id)+" completed!")
t1=threading.Thread(target=worker, args=(1,))
t2=threading.Thread(target=worker, args=(2,))
t1.start()
t2.start()
t1.join()
t2.join()
print("Done!\n"+str(confirmed))
Output Should be like
would you like any frozen pizzas? (y/n)y
How many would you like 1000000
would you like any pastas? (y/n)y
How many would you like 1000000
would you like any pizzas? (y/n)y
How many would you like 1000000
would you like any chicken? (y/n)y
How many would you like 1000000
At what rate would you like to recieve reports? 100000
Frozen pizzas starting...
Pastas starting...
Pizzas starting...
Chicken starting...
100000 Frozen Pizzas completed!
200000 Frozen Pizzas completed!
300000 Frozen Pizzas
completed!
400000 Frozen Pizzas completed!
500000 Frozen Pizzas completed!
600000 Frozen Pizzas completed!
700000 Frozen Pizzas completed!
100000 Chickens completed!
800000 Frozen Pizzas completed!
900000 Frozen Pizzas completed!
1000000 Frozen Pizzas completed!
Frozen Pizzas Complete
100000 Pastas completed!
100000 Pizzas completed!
200000 Chickens completed!
200000 Pizzas completed!
300000 Chickens completed!
300000 Pizzas completed!
200000 Pastas completed!
400000 Chickens completed!
400000 Pizzas completed!
500000 Chickens completed!
300000 Pastas completed!
500000 Pizzas completed!
600000 Chickens completed!
600000 Pizzas completed!
700000 Chickens completed!
400000 Pastas completed!
700000 Pizzas completed!
800000 Chickens completed!
800000 Pizzas completed!
500000 Pastas completed!
900000 Chickens completed!
900000 Pizzas completed!
1000000 Chickens completed!
Chicken Complete
600000 Pastas completed!
1000000 Pizzas completed!
Pizzas Complete
700000 Pastas completed!
800000 Pastas completed!
900000 Pastas completed!
1000000 Pastas completed!
Pastas Complete
Done!
4000000 items made
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.
2. Give at least three examples that show different features of string slices. Describe the feature illustrated by each example. Invent your own examples. Do not copy them for the textbook or any other source.
Input : the input will be a single line containing a positive integer (N).
Out put : output should be a single line containing years, weeks, days values separated by spaces
N is 1329
Polynomial
Given polynomial, write a program that prints polynomial in Cix^Pi + Ci-1x^Pi-1 + .... + C1x + C0 format.Input
The first line contains a single integer N.
Next N lines contain two integers Pi, Ci separated with space, where Pi denotes power and Ci denotes coefficient of Pi.Output
Print the polynomial in the format Cix^Pi + Ci-1x^Pi-1 + .... + C1x + C0, where Pi's are powers in decreasing order, Ci is coefficient, and C0 is constant. There will be space before and after the plus or minus sign.
If the coefficient is zero, then don't print the term.
If the term with the highest degree is negative, the term should represent -Cix^Pi.
For the term where power is 1, represent it as C1x instead of C1x^1.
If the polynomial degree is zero and the constant term is also zero, then print 0 to represent the polynomial.
For term Cix^Pi, if the coefficient of the term Ci is 1, print x^Pi instead of 1x^Pi.Explanation
If N = 4
For power 0, the coefficient is 5
For power 1, the coefficient is 0
For power 2, the coefficient is 10
For power 3, the coefficient is 6.
Then polynomial represents "6x^3 + 10x^2 + 5"Constraints
N <= 100
0 <= Pi < 1000
-1000 <= Ci <= 1000
Sample Input
Sample Output
6x^3 + 10x^2 + 5
7x^4 + 6x^3 + x^2 + 3x + 2