forked from ninas/umonya_notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblems.html
More file actions
126 lines (93 loc) · 4.89 KB
/
problems.html
File metadata and controls
126 lines (93 loc) · 4.89 KB
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Introductory Programming in Python: Flow Control: Functions</title>
<link rel='stylesheet' type='text/css' href='style.css' />
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<script src="animation.js" type="text/javascript">
</script>
</head>
<body onload="animate_loop()">
<div class="page">
<h1>Introductory Programming in Python: <br />
Problem Solving Session</h1>
<div class="centered">
[<a href="functions.html">Prev: Flow Control: Functions</a>] [<a href="index.html">Course Outline</a>] <!-- [<a href="scope.html">Next: Variable Scope</a>]-->
</div>
<p>So now we have teached you the basics of python, now it its time for you to use what
you've learned to solve some problems. The problems you don't finish will become homework that
you should send in along with your test. Do not try and rush with the problems. An accurate solution
shows what you learn, whereas one that is written quickly and doesn't work means nothing</p>
<h2>Sum of multiples</h2>
<p>If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.
The sum of these multiples is 23. <br/><br/>
Write a porgram that inputs a value N, then calculates and prints the sum of all the multiples of 3 or 5 for
the numbers that are less than N.</p>
<h2>Accountants Calculator</h2>
<p>Write an accountants calculator. The user may enter a number, an operator (+, -, *, /), a blank line, or the word 'quit'. The first entry must be a number. Every time a number is entered, it is added to the current total (which
starts at 0), unless the previous line was an operator, in which case, instead of adding, use the operator given to combine the number entered and the total to form a new total. Every time a blank line is entered, print a line of dashes followed by
a line containing the current total. If the entry is the word 'quit' the program ends. Here is an example of output for the input; 4, 9, blank line, *, 2, -, 6, /, 10, blank line, quit
<pre class="listing">
4
9
-----
13
*
2
-
6
/
10
-----
2
quit
</pre></li>
<h2>Sets</h2>
<p>A set in mathematics is a collection of distinct elements.
The union of two sets A and B consists of all unique
elements which are either in set A, or set B, or both set
A and set B. The intersection of two sets A and B
consists of all elements which are in both set A and set
B.</p>
<p>Write a program that reads in two sets of integers, A
and B, and calculates both the union and intersection of
A and B. The new sets must be output in ascending
order, i.e. smallest integers first.</p>
<p>Your program sould look similar to the following</p>
<pre class="listing">
Enter the size of set A: <strong>3</strong>
Enter element 1 of set A: <strong>1</strong>
Enter element 2 of set A: <strong>2</strong>
Enter element 3 of set A: <strong>4</strong>
Enter the size of set B: <strong>4</strong>
Enter element 1 of set B: <strong>2</strong>
Enter element 2 of set B: <strong>4</strong>
Enter element 3 of set B: <strong>6</strong>
Enter element 4 of set B: <strong>8</strong>
A union B: 1 2 4 6 8
A intersect B: 2 4
</pre>
<h2>Decompression</h2>
<p>To save time in the transmission of data, it is often compressed. One simple way of doing this
is to encode lengthy sequences of the same value by using a single instance of that value followed
by the number of times it is repeated. For example if you have a sequence 2222227777
it would be represented as 2 6 7 4.</p>
<p>Your task is to write a program that will receive A and B. The new sets must be output in ascending
as input a sequence of numbers representing encoded data and decompress it. That is, print out
the original sequence in its long form.</p>
<h2>Hidden Strings</h2>
<p>Strings are just a series of characters 'strung' or joined together. Substrings are strings that are, in fact, just a
part of a larger string. One might, for various reasons, wish to find if a string is merely a substring of another
string, sometimes disregarding such things as case (UPPER and lower) or punctuation.</p>
<p>Write a program that reads in two sets of integers, A and B, and calculates both the union and intersection of
A and B. The new sets must be output in ascending order, i.e. smallest integers first.<p>
<div class="centered">
[<a href="functions.html">Prev: Flow Control: Functions</a>] [<a href="index.html">Course Outline</a>] <!-- [<a href="scope.html">Next: Variable Scope</a>]-->
</div>
</div>
<div class="pagefooter">
Copyright © James Dominy 2007-2008; Released under the <a href="http://www.gnu.org/copyleft/fdl.html">GNU Free Documentation License</a><br />
<a href="intropython.tar.gz">Download the tarball</a>
</div>
</body>
</html>