Problem 1:
Create 2 virtual dice. Roll both dice, display the random value of each, and display the result.
Sample output:
First dice: 3
Second dice: 6
You got 9
Write the definition of a class WeatherForecast that provides the following behavior (methods):
No constructor need be defined. Be sure to define instance <span style="text-decoration-line: none;">variables</span> as needed by your "get"/"set" methods.
Write a program that prints all powers of 2 from 20 up to 220.
Output Segment
1
2
4
8
16
:
:
65536
131072
262144
524288
1048576
a. Write a for loop that prints the ASCII code of each character in a string named S. Use the built-in function ord(character) to convert each character to an ASCII integer.
b. Next, change your loop to compute the sum of the ASCII codes of all characters in a string
4. 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]
5. Write a for loop that prints a dictionary's items in sorted (ascending) order
Given a matrix of order M*N and a value K, write a program to rotate each ring of the matrix clockwise by K elements. If in any ring has less than or equal to K elements, then don’t rotate that ring.
The first line of input will be two space-separated integers, denoting the M and N.
The next M lines will contain N space-separated integers.
The next line will contain an integer, denoting K.
The output should be M*N matrix by rotating the matrix by K elements.
For ex, if the given M and N are 4 and 4 respectively. If the matrix elements are
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16If the given K is 3. Rotate each ring of the matrix by 3 elements.
In the above matrix, the elements (1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5) is a ring, similarly, the elements (6, 7, 11, 10) will make a ring.
Therefore, by rotating each ring in clockwise direction by 3 elements will give (13, 9, 5, 1, 2, 3, 4, 8, 12, 16, 15, 14) and (10, 6, 7, 11). So output is
13 9 5 1
14 7 11 2
15 6 10 3
16 12 8 4Given a string, write a program to return the sum and average of the numbers that appear in the string, ignoring all other characters.
Input
The input will be a single line containing a string.
Output
The output should contain the sum and average of the numbers that appear in the string.
Note: Round the average value to two decimal places.
Explanation
For example, if the given string is "I am 25 years and 10 months old", the numbers are 25, 10. Your code should print the sum of the numbers(35) and the average of the numbers(17.5) in the new line.
Input 1:-
I am 25 years and 10 months old
Output 1:-
35
17.5
Input 2:-
Tech Foundation 35567
Output 2:-
35567
35567.0
We want given both inputs they can get both outputs we code was run one by one input and output
Given a string, write a program to return the sum and average of the digits of all numbers that appear in the string, ignoring all other characters.
Input:-
The input will be a single line containing a string.
Output:-
The output should contain the sum and average of the digits of all numbers that appear in the string.
Note:- Round the average value to two decimal places.
Explanation:-
For example, if the given string is "I am 25 years and 10 months old", the digits of all numbers that appear in the string are 2, 5, 1, 0. Your code should print the sum of all digits(8) and the average of all digits(2.0) in the new line.
Input 1:-
I am 25 years and 10 months old
Output 1:-
8
2.0
Input 2:-
Tech Foundation 35567
Output 2:-
26
5.2
Input 3:-
Anjali25 is python4 Expert
Output 3:-
11
3.67
When we give three Inputs one by one they can give exact three Outputs must be come when code can be executed
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
Roman Numerals
Write a program to convert a non-negative integer
N to its Roman numeral representation.Roman numerals are usually written largest to smallest from left to right.
symbol value
I 1
V 5
X 10
L 50
C 100
D 500
M 1000
A number containing several decimal digits is built by appending Roman numeral equivalent for each, from highest to lowest, as in the following examples:
The input will be a single line containing a positive integer N.
The input number not be greater than 104.
Output
The output should be a single line containing representation of Roman Numeral of number N.
See Roman Numerals Table for Symbol and corresponding value.
Sample Input 1
2
Sample Output 1
II
Sample Input 2
1994
Sample Output 2
MCMXCIV