Skip to content

Commit e14f7e4

Browse files
authored
Update README.md
1 parent 973ebf9 commit e14f7e4

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,74 @@
11
# NPTEL-Python-Week-2-Practice-Programming-Assignment
22
NPTEL Python Week 2 Practice Programming Assignment
3+
4+
# Week 2 Practice Programming Assignment
5+
1. Write a function intreverse(n) that takes as input a positive integer n and returns the integer obtained by reversing the digits in n.
6+
7+
Here are some examples of how your function should work.
8+
```python
9+
>>> intreverse(783)
10+
387
11+
12+
>>> intreverse(242789)
13+
987242
14+
15+
>>> intreverse(3)
16+
3
17+
```
18+
19+
2. Write a function matched(s) that takes as input a string s and checks if the brackets "(" and ")" in s are matched: that is, every "(" has a matching ")" after it and every ")" has a matching "(" before it. Your function should ignore all other symbols that appear in s. Your function should return True if s has matched brackets and False if it does not.
20+
21+
Hint: Keep track of the nesting depth of brackets. Initially the depth is 0. The depth increases with each opening bracket and decreases with each closing bracket. What are the constraints on the value of the nesting depth for all brackets to be matched?
22+
23+
Here are some examples to show how your function should work.
24+
```python
25+
>>> matched("zb%78")
26+
True
27+
28+
>>> matched("(7)(a")
29+
False
30+
31+
>>> matched("a)*(?")
32+
False
33+
34+
>>> matched("((jkl)78(A)&l(8(dd(FJI:),):)?)")
35+
True
36+
```
37+
38+
3. Write a function sumprimes(l) that takes as input a list of integers l and retuns the sum of all the prime numbers in l.
39+
40+
Here are some examples to show how your function should work.
41+
```python
42+
>>> sumprimes([3,3,1,13])
43+
19
44+
45+
>>> sumprimes([2,4,6,9,11])
46+
13
47+
48+
>>> sumprimes([-3,1,6])
49+
0
50+
```
51+
52+
# Sample Test Cases
53+
| | Input | Output |
54+
|--------------|---------------------------------------------------|-----------------|
55+
| Test Case 1 | intreverse(31511) | 11513 |
56+
| Test Case 2 | intreverse(4) | 4 |
57+
| Test Case 3 | intreverse(15135324234235) | 53243242353151 |
58+
| Test Case 4 | matched("a3qw3;4w3(aasdgsd)((agadsgdsgag)agaga)") | True |
59+
| Test Case 5 | matched("(ag(Gaga(agag)Gaga)GG)a)33)cc(") | False |
60+
| Test Case 6 | matched("(adsgdsg(agaga)a") | False |
61+
| Test Case 7 | matched("15ababa.agaga[][[[") | True |
62+
| Test Case 8 | sumprimes([101,93,97,44]) | 198 |
63+
| Test Case 9 | sumprimes([1001,393,743,59]) | 802 |
64+
| Test Case 10 | sumprimes([11,11,11,13,11,-11]) | 57 |
65+
| Test Case 11 | intreverse(31511) | 11513 |
66+
| Test Case 12 | intreverse(4) | 4 |
67+
| Test Case 13 | intreverse(15135324234235) | 53243242353151 |
68+
| Test Case 14 | matched("a3qw3;4w3(aasdgsd)((agadsgdsgag)agaga)") | True |
69+
| Test Case 15 | matched("(ag(Gaga(agag)Gaga)GG)a)33)cc(") | False |
70+
| Test Case 16 | matched("(adsgdsg(agaga)a") | False |
71+
| Test Case 17 | matched("15ababa.agaga[][[[") | True |
72+
| Test Case 18 | sumprimes([101,93,97,44]) | 198 |
73+
| Test Case 19 | sumprimes([1001,393,743,59]) | 802 |
74+
| Test Case 20 | sumprimes([11,11,11,13,11,-11]) | 57 |

0 commit comments

Comments
 (0)