6phrase - Myslate - Python - Session Plan

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 19

Six Phrase - mySLATE

Day 1
1. Write a program which will find all such numbers which are divisible by 7 but
are not a multiple of 5, between 2000 and 3200 (both included).The numbers
obtained should be printed in a comma-separated sequence on a single line.

2. Write a program which can compute the factorial of a given numbers.The


results should be printed in a comma-separated sequence on a single
line.Suppose the following input is supplied to the program: 8 Then, the output
should be:40320

3. With a given integral number n, write a program to generate a dictionary that


contains (i, i x i) such that is an integral number between 1 and n (both
included). and then the program should print the dictionary.Suppose the
following input is supplied to the program: 8

Then, the output should be:

{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}

Day 2
4. Write a program which accepts a sequence of comma-separated numbers from
console and generate a list and a tuple which contains every number.Suppose
the following input is supplied to the program:
34,67,55,33,12,98
Then, the output should be:
['34', '67', '55', '33', '12', '98']
('34', '67', '55', '33', '12', '98')

5. Define a class which has at least two methods:

getString: to get a string from console input

printString: to print the string in upper case.

Also please include simple test function to test the class methods.

6. Write a program that calculates and prints the value according to the given
formula:
Q = Square root of [(2 * C * D)/H]
Six Phrase - mySLATE

Following are the fixed values of C and H:


C is 50. H is 30.
D is the variable whose values should be input to your program in a comma-
separated sequence.For example Let us assume the following comma separated
input sequence is given to the program:
100,150,180
The output of the program should be:
18,22,24
7. Write a program which takes 2 digits, X,Y as input and generates a 2-
dimensional array. The element value in the i-th row and j-th column of the
array should be i * j.
Note: i=0,1.., X-1; j=0,1,¡Y-1. Suppose the following inputs are given to the
program: 3,5
Then, the output of the program should be:

[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]

8. Write a program that accepts a comma separated sequence of words as input


and prints the words in a comma-separated sequence after sorting them
alphabetically.
Suppose the following input is supplied to the program:
without,hello,bag,world
Then, the output should be:
bag,hello,without,world

9. Write a program that accepts sequence of lines as input and prints the lines
after making all characters in the sentence capitalized.
Suppose the following input is supplied to the program:
Hello world
Practice makes perfect
Then, the output should be:
HELLO WORLD
PRACTICE MAKES PERFECT

Day 3
10. Write a program that accepts a sequence of whitespace separated words as
input and prints the words after removing all duplicate words and sorting them
alphanumerically.
Suppose the following input is supplied to the program:
Six Phrase - mySLATE

hello world and practice makes perfect and hello world again
Then, the output should be:

again and hello makes perfect practice world

11. Write a program which accepts a sequence of comma separated 4 digit binary
numbers as its input and then check whether they are divisible by 5 or not. The
numbers that are divisible by 5 are to be printed in a comma separated
sequence.
Example:
0100,0011,1010,1001
Then the output should be:
1010

12. Write a program, which will find all such numbers between 1000 and 3000
(both included) such that each digit of the number is an even number.The
numbers obtained should be printed in a comma-separated sequence on a
single line.
13. Write a program that accepts a sentence and calculate the number of letters
and digits.

Suppose the following input is supplied to the program:

hello world! 123


Then, the output should be:

LETTERS 10
DIGITS 3
14. Write a program that computes the value of a+aa+aaa+aaaa with a given digit
as the value of a.

Suppose the following input is supplied to the program:

9
Then, the output should be:

11106

Day 4
15. Use a list comprehension to square each odd number in a list. The list is input
by a sequence of comma-separated numbers. Suppose the following input is
supplied to the program:
Six Phrase - mySLATE

1,2,3,4,5,6,7,8,9
Then, the output should be:

1,9,25,49,81

16. Write a program that computes the net amount of a bank account based a
transaction log from console input. The transaction log format is shown as
following:
D 100
W 200
D means deposit while W means withdrawal.
Suppose the following input is supplied to the program:
D 300
D 300
W 200
D 100
Then, the output should be:

500

17. Longest Common Subsequence


Six Phrase - mySLATE

Day 5 and Day 6


18. A website requires the users to input username and password to register. Write
a program to check the validity of password input by users.
Following are the criteria for checking the password:

 At least 1 letter between [a-z]

 At least 1 number between [0-9]

 At least 1 letter between [A-Z]

 At least 1 character from [$#@]

 Minimum length of transaction password: 6

 Maximum length of transaction password: 12

Your program should accept a sequence of comma separated passwords and


will check them according to the above criteria. Passwords that match the
criteria are to be printed, each separated by a comma.
Example
If the following passwords are given as input to the program:
ABd1234@1,a F1#,2w3E*,2We3345
Then, the output of the program should be:
ABd1234@1

19. You are required to write a program to sort the (name, age, score) tuples by
ascending order where name is string, age and score are numbers. The tuples
are input by console. The sort criteria is:

o 1: Sort based on name

o 2: Then sort based on age

o 3: Then sort by score

The priority is that name > age > score.


If the following tuples are given as input to the program:
Tom,19,80
John,20,90
Six Phrase - mySLATE

Jony,17,91
Jony,17,93
Json,21,85
Then, the output of the program should be:

[('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Json', '21', '85'), ('Tom',
'19', '80')]
Six Phrase - mySLATE

20. Define a class with a generator which can iterate the numbers, which are
divisible by 7, between a given range 0 and n.
21. A robot moves in a plane starting from the original point (0,0). The robot can
move toward UP, DOWN, LEFT and RIGHT with a given steps. The trace of robot
movement is shown as the following:

UP 5
DOWN 3
LEFT 3
RIGHT 2

The numbers after the direction are steps. Please write a program to compute
the distance from current position after a sequence of movement and original
point. If the distance is a float, then just print the nearest integer. Example: If
the following tuples are given as input to the program:

UP 5
DOWN 3
LEFT 3
RIGHT 2
Then, the output of the program should be:

22. Write a program to compute the frequency of the words from the input. The
output should output after sorting the key alphanumerically.

Suppose the following input is supplied to the program:

New to Python or choosing between Python 2 and Python 3? Read Python 2 or


Python 3.
Then, the output should be:

2:2
3.:1
3?:1
New:1
Python:5
Read:1
and:1
between:1
choosing:1
or:2
to:1

23. Write a method which can calculate square value of number


Six Phrase - mySLATE

24. Python has many built-in functions, and if you do not know how to use it, you
can read document online or find some books. But Python has a built-in
document function for every built-in functions.
Please write a program to print some Python built-in functions documents, such
as abs(), int(), raw_input()
And add document for your own function
25. Define a class, which have a class parameter and have a same instance
parameter.
26. Define a function that can convert a integer into a string and print it in
console.
27. Define a function that can receive two integer numbers in string form and
compute their sum and then print it in console.
28. Define a function which can compute the sum of two numbers.
29. Define a function that can accept two strings as input and concatenate them
and then print it in console.
30. Define a function that can accept two strings as input and print the string with
maximum length in console. If two strings have the same length, then the
function should print all strings line by line.
31. Longest Common Substring

Day 7
32. Define a function which can print a dictionary where the keys are numbers
between 1 and 20 (both included) and the values are square of keys.
33. Define a function which can generate a dictionary where the keys are numbers
between 1 and 20 (both included) and the values are square of keys. The
function should just print the keys only.
34. Define a function which can generate and print a list where the values are
square of numbers between 1 and 20 (both included).
35. Define a function which can generate a list where the values are square of
numbers between 1 and 20 (both included). Then the function needs to print
the first 5 elements in the list.
36. Define a function which can generate a list where the values are square of
numbers between 1 and 20 (both included). Then the function needs to print
the last 5 elements in the list.
37. Define a function which can generate a list where the values are square of
numbers between 1 and 20 (both included). Then the function needs to print
all values except the first 5 elements in the list.
38. Define a function which can generate and print a tuple where the value are
square of numbers between 1 and 20 (both included).
39. Longest Palindromic Subsequence
Six Phrase - mySLATE

Day 8
40. With a given tuple (1,2,3,4,5,6,7,8,9,10), write a program to print the first
half values in one line and the last half values in one line.
41. Write a program to generate and print another tuple whose values are even
numbers in the given tuple (1,2,3,4,5,6,7,8,9,10).
42. Write a program which accepts a string as input to print "Yes" if the string is
"yes" or "YES" or "Yes", otherwise print "No".
43. Write a program which can map() to make a list whose elements are square of
elements in [1,2,3,4,5,6,7,8,9,10].
44. Write a program which can map() and filter() to make a list whose elements
are square of even number in [1,2,3,4,5,6,7,8,9,10].
45. Write a program which can filter() to make a list whose elements are even
number between 1 and 20 (both included).
46. Longest Increasing Subsequence
47. Kadane’s Algorithm

Day 9
48. Write a program which can map() to make a list whose elements are square of
numbers between 1 and 20 (both included).
49. Define a class named American which has a static method called
printNationality.
50. Define a class named American and its subclass NewYorker.
51. Longest Palindromic Subsequence
52. Find the largest kxk submatrix with all entries 1 in a mxn binary matrix

Day 10
53. Define a class named Circle which can be constructed by a radius. The Circle
class has a method which can compute the area.

54. Define a class named Rectangle which can be constructed by a length and
width. The Rectangle class has a method which can compute the area.
Six Phrase - mySLATE

55. Define a class named Shape and its subclass Square. The Square class has an
init function which takes a length as argument. Both classes have a area
function which can print the area of the shape where Shape's area is 0 by
default.

56. Please raise a RuntimeError exception.

57. Minimum Cost Path

Day 11
58. Write a function to compute 5/0 and use try/except to catch the exceptions.

59. Define a custom exception class which takes a string message as attribute.
60. Assuming that we have some email addresses in the
"[email protected]" format, please write program to print the user
name of a given email address. Both user names and company names are
composed of letters only.
Example: If the following email address is given as input to the program:
[email protected]
Then, the output of the program should be:
john
In case of input data being supplied to the question, it should be assumed to be
a console input.

61. The coin change Problem

Day 12
62. Assuming that we have some email addresses in the
"[email protected]" format, please write program to print the
company name of a given email address. Both user names and company names
are composed of letters only.
Example: If the following email address is given as input to the program:
[email protected]
Then, the output of the program should be:
google
In case of input data being supplied to the question, it should be assumed to be
a console input.
Six Phrase - mySLATE

63. Write a program which accepts a sequence of words separated by whitespace


as input to print the words composed of digits only.

Example: If the following words is given as input to the program:


2 cats and 3 dogs.
Then, the output of the program should be:
['2', '3']
In case of input data being supplied to the question, it should be assumed to be
a console input.

64. Print a unicode string "hello world".


65. Write a program to read an ASCII string and to convert it to a unicode string
encoded by utf-8.
66. Write a special comment to indicate a Python source code file is in unicode.
67. Write a program to compute 1/2+2/3+3/4+...+n/n+1 with a given n input by
console (n>0).

Example: If the following n is given as input to the program:

5
Then, the output of the program should be:

3.55
In case of input data being supplied to the question, it should be assumed to be
a console input.

68. Write a program to compute:

f(n)=f(n-1)+100 when n>0


and f(0)=1
with a given n input by console (n>0).

Example: If the following n is given as input to the program:

5
Then, the output of the program should be:

500
In case of input data being supplied to the question, it should be assumed to be
a console input.

69. The Fibonacci Sequence is computed based on the following formula:

f(n)=0 if n=0
f(n)=1 if n=1
f(n)=f(n-1)+f(n-2) if n>1
Six Phrase - mySLATE

Please write a program to compute the value of f(n) with a given n input by
console.

Example: If the following n is given as input to the program:

7
Then, the output of the program should be:

13
In case of input data being supplied to the question, it should be assumed to be
a console input.

70. The Fibonacci Sequence is computed based on the following formula:

f(n)=0 if n=0
f(n)=1 if n=1
f(n)=f(n-1)+f(n-2) if n>1
Please write a program to compute the value of f(n) with a given n input by
console.

Example: If the following n is given as input to the program:

7
Then, the output of the program should be:

0,1,1,2,3,5,8,13
In case of input data being supplied to the question, it should be assumed to be
a console input.

71. Please write a program using generator to print the even numbers between 0
and n in comma separated form while n is input by console.

Example: If the following n is given as input to the program:

10
Then, the output of the program should be:

0,2,4,6,8,10
In case of input data being supplied to the question, it should be assumed to be
a console input.

72. Please write a program using generator to print the numbers which can be
divisible by 5 and 7 between 0 and n in comma separated form while n is input
by console.

Example: If the following n is given as input to the program:

100
Six Phrase - mySLATE

Then, the output of the program should be:

0,35,70
In case of input data being supplied to the question, it should be assumed to be
a console input.

Day 13
73. Please write assert statements to verify that every number in the list [2,4,6,8]
is even.

74. Please write a program which accepts basic mathematic expression from
console and print the evaluation result.

Example: If the following n is given as input to the program:

35 + 3
Then, the output of the program should be:

38
75. Please write a binary search function which searches an item in a sorted list.
The function should return the index of element to be searched in the list.
76. Please generate a random float where the value is between 10 and 100 using
Python module.
77. Please generate a random float where the value is between 5 and 95 using
Python module.
78. Subset Sum Problem

Day 14
79. Please write a program to output a random even number between 0 and 10
inclusive using random module and list comprehension.
80. Please write a program to output a random number, which is divisible by 5 and
7, between 10 and 150 inclusive using random module and list comprehension.
81. Please write a program to generate a list with 5 random numbers between 100
and 200 inclusive.
82. Please write a program to randomly generate a list with 5 even numbers
between 100 and 200 inclusive.
83. Please write a program to randomly generate a list with 5 numbers, which are
divisible by 5 and 7 , between 1 and 1000 inclusive.
Six Phrase - mySLATE

84. 0/1 Knapsack Problem

Day 15
85. Please write a program to randomly print a integer number between 7 and 15
inclusive.
86. Please write a program to compress and decompress the string "hello world!
hello world!hello world!hello world!".
87. Please write a program to print the running time of execution of "1+1" for 100
times.
88. Please write a program to shuffle and print the list [3,6,7,8].
89. Please write a program to generate all sentences where subject is in ["I",
"You"] and verb is in ["Play", "Love"] and the object is in ["Hockey","Football"].
90. Largest Area Histogram Problem

Day 16
91. Please write a program to print the list after removing even numbers in
[5,6,77,45,22,12,24].
92. By using list comprehension, please write a program to print the list after
removing numbers which are divisible by 5 and 7 in [12,24,35,70,88,120,155].
93. By using list comprehension, please write a program to print the list after
removing the 0th, 2nd, 4th,6th numbers in [12,24,35,70,88,120,155].

94. By using list comprehension, please write a program to print the list after
removing the 2nd - 4th numbers in [12,24,35,70,88,120,155].
95. By using list comprehension, please write a program generate a 3*5*8 3D array
whose each element is 0.
96. Knight’s Tour Problem

Day 17
97. By using list comprehension, please write a program to print the list after
removing the 0th,4th,5th numbers in [12,24,35,70,88,120,155].
Six Phrase - mySLATE

98. By using list comprehension, please write a program to print the list after
removing the value 24 in [12,24,35,24,88,120,155].
99. With two given lists [1,3,6,78,35,55] and [12,24,35,24,88,120,155], write a
program to make a list whose elements are intersection of the above given
lists.
100. With a given list [12,24,35,24,88,120,155,88,120,155], write a program to
print this list after removing all duplicate values with original order reserved.
101. Define a class Person and its two child classes: Male and Female. All classes
have a method "getGender" which can print "Male" for Male class and "Female"
for Female class.
102. Egg Drop Problem

Day 18
103. Please write a program which count and print the numbers of each character
in a string input by console.
Example: If the following string is given as input to the program:

abcdefgabc
Then, the output of the program should be:

a,2
c,2
b,2
e,1
d,1
g,1
f,1
104. Please write a program which accepts a string from console and print it in
reverse order.
Example: If the following string is given as input to the program:*

rise to vote sir


Then, the output of the program should be:

ris etov ot esir

105. Please write a program which accepts a string from console and print the
characters that have even indexes.
Example: If the following string is given as input to the program:

H1e2l3l4o5w6o7r8l9d
Then, the output of the program should be:
Six Phrase - mySLATE

Helloworld

106. Please write a program which prints all permutations of [1,2,3]


107. Write a program to solve a classic ancient Chinese puzzle: We count 35 heads
and 94 legs among the chickens and rabbits in a farm. How many rabbits and
how many chickens do we have?
108. N Queen Problem

Day 19

109. Given the participants' score sheet for your University Sports Day, you are
required to find the runner-up score. You are given scores. Store them in a list
and find the score of the runner-up.

If the following string is given as input to the program:

23665

Then, the output of the program should be:

110. You are given a string S and width W. Your task is to wrap the string into a
paragraph of width.

If the following string is given as input to the program:

ABCDEFGHIJKLIMNOQRSTUVWXYZ

Then, the output of the program should be:

ABCD

EFGH

IJKL

IMNO
Six Phrase - mySLATE

QRST

UVWX

YZ

111. You are given an integer, N. Your task is to print an alphabet rangoli of size
N. (Rangoli is a form of Indian folk art based on creation of patterns.)

Different sizes of alphabet rangoli are shown below:

#size 3

----c----

--c-b-c--

c-b-a-b-c

--c-b-c--

----c----

#size 5

--------e--------

------e-d-e------

----e-d-c-d-e----

--e-d-c-b-c-d-e--

e-d-c-b-a-b-c-d-e

--e-d-c-b-c-d-e--

----e-d-c-d-e----

------e-d-e------

--------e--------
Six Phrase - mySLATE

Day 20
112. You are given a date. Your task is to find what the day is on that date.

Input

A single line of input containing the space separated month, day and year,
respectively, in MM DD YYYY format.

08 05 2015

Output

Output the correct day in capital letters.

WEDNESDAY

113. Given 2 sets of integers, M and N, print their symmetric difference in


ascending order. The term symmetric difference indicates those values that
exist in either M or N but do not exist in both.

Input

The first line of input contains an integer, M.The second line contains M space-
separated integers.The third line contains an integer, N.The fourth line
contains N space-separated integers.

2459

2 4 11 12

Output

Output the symmetric difference integers in ascending order, one per line.

11

12
Six Phrase - mySLATE

114. You are given words. Some words may repeat. For each word, output its
number of occurrences. The output order should correspond with the input
order of appearance of the word. See the sample input/output for clarification.

If the following string is given as input to the program:

bcdef

abcdefg

bcde

bcdef

Then, the output of the program should be:

211

115. You are given a string.Your task is to count the frequency of letters of the
string and print the letters in descending order of frequency.

If the following string is given as input to the program:

aabbbccde
Then, the output of the program should be:

b3
a2
c2

116. Chess Promotion Problem

You might also like