1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
Exercises
=========
1. Round a float to the nearest integer using ``int()``.
#. What does this do? round(amount * 10)/10.0. How to round it to the nearest
5 paise?
#. Print out the fibonacci sequence less than 30
#. Write a program that prints the numbers from 1 to 100. But for multiples
of three print "Fizz" instead of the number and for the multiples of five
print "Buzz". For numbers which are multiples of both three and five print
"FizzBuzz". This is famously known as the FizzBuzz test.
#. Write a program that displays all three digit numbers that are equal to
the sum of the cubes of their digits. That is, print numbers :math:`$abc$`
that have the property :math:`$abc = a^3 + b^3 + c^3$` These are called
:math:`$Armstrong$` numbers.
#. Collatz sequence
#. Start with an arbitrary (positive) integer.
#. If the number is even, divide by 2; if the number is odd multiply by 3
and add 1.
#. Repeat the procedure with the new number.
#. There is a cycle of 4, 2, 1 at which the procedure loops.
Write a program that accepts the starting value and prints out the Collatz
sequence.
#. Kaprekar's constant
#. Take a four digit number–with at least two digits different.
#. Arrange the digits in ascending and descending order, giving A and D
respectively.
#. Leave leading zeros in A!
#. Subtract A from D.
#. With the result, repeat from step 2.
Write a program to accept a 4-digit number and display the progression to
Kaprekar’s constant.
#. Write a program that prints the following pyramid on the screen.
::
1
2 2
3 3 3
4 4 4 4
The number of lines must be obtained from the user as input. When can your
code fail?
#. Write a function to return the gcd of two numbers.
#. Write a program to find Primitive Pythagorean Triads A pythagorean triad
:math:`$(a,b,c)$` has the property :math:`$a^2 + b^2 = c^2$`. By primitive
we mean triads that do not ‘depend’ on others. For example, (4,3,5) is a
variant of (3,4,5) and hence is not primitive. And (10,24,26) is easily
derived from (5,12,13) and should not be displayed by our program. Write a
program to print primitive pythagorean triads. The program should generate
all triads with a, b values in the range 0—100
#. Write a program that generates a list of all four digit numbers that have
all their digits even and are perfect squares. For example, the output
should include 6400 but not 8100 (one digit is odd) or 4248 (not a perfect
square).
#. The aliquot of a number is defined as: the sum of the *proper* of the
number.
For example, the ``aliquot(12) = 1 + 2 + 3 + 4 + 6 = 16``.
Write a function that returns the aliquot number of a given number.
#. A pair of numbers (a, b) is said to be *amicable* if the aliquot number of
a is b and the aliquot number of b is a.
Example: ``220, 284``
Write a program that prints all five digit amicable pairs.
#. Given an empty chessboard and one Bishop placed in any square, say (r, c),
generate the list of all squares the Bishop could move to.
#. Write a program to display the following pyramid. The number of lines
in the pyramid should not be hard-coded. It should be obtained from
the user. The pyramid should appear as close to the centre of the
screen as possible.
::
*
***
*****
*******
#. Write a program to display the following pyramid. The number of lines
in the pyramid should not be hard-coded. It should be obtained from
the user. The pyramid should appear as close to the centre of the
screen as possible.
::
*
* *
* * *
* * * *
#. Write a program to display the following pyramid. The number of lines
has to be a parameter obtained from the user. The pyramid must appear
aligned to the left edge of the screen.
::
1
2 2
3 3 3
4 4 4 4
#. Write a program to display the following pyramid. The number of lines
has to be a parameter obtained from the user. The pyramid must appear
aligned to the left edge of the screen.
::
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
#. Write a program to display the following output. The last number
where the program will stop printing has to be a parameter obtained
from the user. The pyramid must appear aligned to the left edge of
the screen. Note that depending on the last number, the base of the
pyramid may be smaller than the line above it.
::
1
2 3
4 5 6
7 8 9 10
11 12
#. Given a string like, "1, 3-7, 12, 15, 18-21", produce the list
``[1,3,4,5,6,7,12,15,18,19,20,21]``
#. You are given date strings of the form “29, Jul 2009”, or “4 January
2008”. In other words a number a string and another number, with a comma
sometimes separating the items.Write a function that takes such a string
and returns a tuple (yyyy, mm, dd) where all three elements are ints.
#. Count word frequencies in a file.
#. Given a dictionary of the names of students and their marks, identify how
many duplicate marks are there? and what are these?
#. Given a string of the form "4-7, 9, 12, 15" find the numbers missing in
this list for a given range.
..
Local Variables:
mode: rst
indent-tabs-mode: nil
sentence-end-double-space: nil
fill-column: 77
End:
|