import numpy as np
old = no.array([[1, 1, 1], [1, 1, 1]])
new = old
new[0, :2] = 0
print(old)
Type the expressions below in python interactively, and try to explain what's happening in each case: a. 2 ** 16 2 / 5, 2 / 5.0 b. "spam" + "eggs" S = "ham" "eggs " + S S * 5 S[:0] "green %s and %s" % ("eggs", S) c. ('x',) [0] ('x', 'y') [1] d. L = [1,2,3] + [4,5,6] L, L[:], L[:0], L[-2], L[-2:] ([1,2,3] + [4,5,6]) [2:4] [L[2], L[3]] L.reverse(); L L.sort(); L L.index(4)
1.Use a for loop and the list append method to generate the powers of 2 to produce the following result [1, 2, 4, 8, 16, 32, 64, 128]
2.Write a for loop that prints a dictionary's items in sorted (ascending) order
Write a python script that get Room No, Room Rent per day, Number of days stayed in and extra charges (breakfast, lunch, and dinner) and display total bill to customer.
Type the expressions below in python interactively, and try to explain what's happening in each case: a. 2 ** 16 2 / 5, 2 / 5.0 b. "spam" + "eggs" S = "ham" "eggs " + S S * 5 S[:0] "green %s and %s" % ("eggs", S) c. ('x',) [0] ('x', 'y') [1] d. L = [1,2,3] + [4,5,6] L, L[:], L[:0], L[-2], L[-2:] ([1,2,3] + [4,5,6]) [2:4] [L[2], L[3]] L.reverse(); L L.sort(); L L.index(4)
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
Add two polynomials
Given two polynomials A and B, write a program that adds the given two polynomials A and B
Output
Print the addition of polynomials A and B.
If the degree of polynomial is zero and the constant term is also zero, then just print 0 to represent the polynomial.
For term Cix^Pi, if the coefficient of the term Ci is 1, simply print x^Pi instead of 1x^Pi.Explanation
Sample Input 1:-
6
0 -20
1 23
2 30
3 19
4 6
5 17
9
0 -100
5 -89
6 -20
7 -1
1 20
2 4
3 99
4 -45
8 12
Sample Output 1:-
12x^8 - x^7 - 20x^6 - 72x^5 - 39x^4 + 118x^3 + 34x^2 + 43x - 120
Note :- Need Space between - and + operators
Sample Input 2:-
4
0 5
1 0
2 10
3 6
3
0 1
1 2
2 4
Sample Output 2:-
6x^3 + 14x^2 + 2x + 6
Note:- Need Space between - and + operators
Given a string, write a program to print a secret message that replaces characters with numbers 'a' with 1, 'b' with 2, ..., 'z' with 26 where characters are separated by '-'.
Note: You need to replace both uppercase and lowercase characters. You can ignore replacing all characters that are not letters.
Input:-
The input will be a string in the single line containing spaces and letters (both uppercase and lowercase).
Output:-
The output should be a single line containing the secret message. All characters in the output should be in lower case.
For Example -
Input 1:-
python
Output 1:-
16-25-20-8-15-14
Input 2:-
Foundations
Output 2:-
6-15-21-14-4-1-20-9-15-14-19
Input 3:-
python learning
Output 3:-
16-25-20-8-15-14 12-5-1-18-14-9-14-7
When we give three Inputs one by one they can give exact three Outputs must be come when code can be executed
ANG IYONG KAPALARAN sa 2030 PROGRAM
Create a list with following items:
(Pwede mong dagdagan ang items)
Then the program should ask for your name and birth year and compute your age. The program should display the randomly picked item on list.
Note: Do not use random.choice() function
Sample output:
Enter your name: Carlo
Enter your Birth Year: 1999
Carlo, Ang iyong edad ay 31 at Ikaw ay Sinungaling parin sa 2030