You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> ***Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5,
7
-
between 2000 and 3200 (both included).The numbers obtained should be printed in a comma-separated sequence on a single line.***
5
+
> **_Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5,
6
+
> between 2000 and 3200 (both included).The numbers obtained should be printed in a comma-separated sequence on a single line._**
7
+
8
+
---
9
+
10
+
### Hints:
8
11
9
-
--------------------------------------
10
-
### Hints:
11
-
> ***Consider use range(#begin, #end) method.***
12
+
> **_Consider use range(#begin, #end) method._**
12
13
13
-
---------------------------------------
14
+
---
14
15
15
16
**Main author's Solution: Python 2**
17
+
16
18
```python
17
19
l=[]
18
20
for i inrange(2000, 3201):
@@ -21,30 +23,42 @@ for i in range(2000, 3201):
21
23
22
24
print','.join(l)
23
25
```
24
-
----------------------------------------
26
+
27
+
---
25
28
26
29
**My Solution: Python 3**
30
+
-**Using for loops**
31
+
27
32
```python
28
33
for i inrange(2000,3201):
29
34
if i%7==0and i%5!=0:
30
35
print(i,end=',')
31
36
print("\b")
32
37
```
33
-
-------------------------------
34
38
39
+
---
40
+
-**Using generators and list comprehension**
41
+
42
+
```python
43
+
print(*(i for i inrange(2000, 3201) if i%7==0and i%5!=0), sep=",")
44
+
```
35
45
# Question 2
36
46
37
47
### **Question:**
38
48
39
-
> ***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
40
-
Then, the output should be:40320***
49
+
> **_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
50
+
> Then, the output should be:40320_**
51
+
52
+
---
41
53
42
-
--------------------
43
54
### Hints:
44
-
>***In case of input data being supplied to the question, it should be assumed to be a console input.***
45
55
46
-
---------------
56
+
> **_In case of input data being supplied to the question, it should be assumed to be a console input._**
57
+
58
+
---
59
+
47
60
**Main author's Solution: Python 2**
61
+
48
62
```python
49
63
deffact(x):
50
64
if x ==0:
@@ -54,58 +68,66 @@ def fact(x):
54
68
x =int(raw_input())
55
69
print fact(x)
56
70
```
57
-
------------
71
+
72
+
---
73
+
58
74
**My Solution: Python 3**
59
75
60
-
***Using While Loop**
61
-
```python
62
-
n =int(raw_input()) #input() function takes input as string type
63
-
#int() converts it to integer type
64
-
fact =1
65
-
i =1
66
-
while i <= n:
67
-
fact = fact * i;
68
-
i = i +1
69
-
print(fact)
70
-
```
71
-
***Using For Loop**
72
-
```python
73
-
n =int(input()) #input() function takes input as string type
74
-
#int() converts it to integer type
75
-
fact =1
76
-
for i inrange(1,n+1):
77
-
fact = fact * i
78
-
print(fact)
79
-
```
80
-
***Using Lambda Function**
81
-
```python
82
-
# Solution by: harshraj22
83
-
84
-
n =int(input())
85
-
defshortFact(x): return1if x <=1else x*shortFact(x-1)
86
-
print(shortFact(n))
87
-
88
-
```
89
-
-------------------
76
+
-**Using While Loop**
77
+
```python
78
+
n =int(input()) #input() function takes input as string type
79
+
#int() converts it to integer type
80
+
fact =1
81
+
i =1
82
+
while i <= n:
83
+
fact = fact * i;
84
+
i = i +1
85
+
print(fact)
86
+
```
87
+
-**Using For Loop**
88
+
```python
89
+
n =int(input()) #input() function takes input as string type
90
+
#int() converts it to integer type
91
+
fact =1
92
+
for i inrange(1,n+1):
93
+
fact = fact * i
94
+
print(fact)
95
+
```
96
+
-**Using Lambda Function**
97
+
98
+
```python
99
+
# Solution by: harshraj22
100
+
101
+
n =int(input())
102
+
defshortFact(x): return1if x <=1else x*shortFact(x-1)
103
+
print(shortFact(n))
104
+
105
+
```
106
+
107
+
---
90
108
91
109
# Question 3
92
110
93
111
### **Question:**
94
112
95
-
>***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 1and n (both included). and then the program should print the dictionary.Suppose the following inputis supplied to the program: 8***
113
+
> **_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_**
>***In case of input data being supplied to the question, it should be assumed to be a console input.Consider use dict()***
121
+
---
105
122
106
-
-----------------
123
+
### Hints:
124
+
125
+
> **_In case of input data being supplied to the question, it should be assumed to be a console input.Consider use dict()_**
126
+
127
+
---
107
128
108
129
**Main author's Solution: Python 2**
130
+
109
131
```python
110
132
n =int(raw_input())
111
133
d =dict()
@@ -115,27 +137,31 @@ print d
115
137
```
116
138
117
139
**My Solution: Python 3:**
140
+
141
+
-**Using for loop**
142
+
118
143
```python
119
144
n =int(input())
120
145
ans = {}
121
146
for i inrange (1,n+1):
122
147
ans[i] = i * i
123
148
print(ans)
124
149
```
125
-
**OR**
150
+
151
+
-**Using dictionary comprehension**
152
+
126
153
```python
127
-
# This is done with dictionary comprehension method
128
154
n =int(input())
129
155
ans={i : i*i for i inrange(1,n+1)}
130
156
print(ans)
131
157
```
132
-
----------------------------------
133
158
134
-
## Conclusion
135
-
***These was the solved problems of day 1. The above problems are very easy for the basic syntex learners.I have shown some easy ways of coding in my solutions. Lets see how to face and attack new problems in the next day.***
159
+
---
136
160
137
-
[***go to next day***](https://github.com/darkprinx/100-plus-Python-programming-exercises-extended/blob/master/Status/Day%202.md"Next Day")
161
+
## Conclusion
138
162
163
+
**_These was the solved problems of day 1. The above problems are very easy for the basic syntex learners.I have shown some easy ways of coding in my solutions. Lets see how to face and attack new problems in the next day._**
139
164
165
+
[**_go to next day_**](https://github.com/darkprinx/100-plus-Python-programming-exercises-extended/blob/master/Status/Day%202.md"Next Day")
0 commit comments