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 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
53
-
Then, the output should be:40320***
59
+
> **_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
60
+
> Then, the output should be:40320_**
61
+
62
+
---
54
63
55
-
--------------------
56
64
### Hints:
57
-
>***In case of input data being supplied to the question, it should be assumed to be a console input.***
58
65
59
-
---------------
66
+
> **_In case of input data being supplied to the question, it should be assumed to be a console input._**
67
+
68
+
---
69
+
60
70
**Main author's Solution: Python 2**
71
+
61
72
```python
62
73
deffact(x):
63
74
if x ==0:
@@ -67,58 +78,66 @@ def fact(x):
67
78
x =int(raw_input())
68
79
print fact(x)
69
80
```
70
-
------------
81
+
82
+
---
83
+
71
84
**My Solution: Python 3**
72
85
73
-
***Using While Loop**
74
-
```python
75
-
n =int(input()) #input() function takes input as string type
76
-
#int() converts it to integer type
77
-
fact =1
78
-
i =1
79
-
while i <= n:
80
-
fact = fact * i;
81
-
i = i +1
82
-
print(fact)
83
-
```
84
-
***Using For Loop**
85
-
```python
86
-
n =int(input()) #input() function takes input as string type
87
-
#int() converts it to integer type
88
-
fact =1
89
-
for i inrange(1,n+1):
90
-
fact = fact * i
91
-
print(fact)
92
-
```
93
-
***Using Lambda Function**
94
-
```python
95
-
# Solution by: harshraj22
96
-
97
-
n =int(input())
98
-
defshortFact(x): return1if x <=1else x*shortFact(x-1)
99
-
print(shortFact(n))
100
-
101
-
```
102
-
-------------------
86
+
-**Using While Loop**
87
+
```python
88
+
n =int(input()) #input() function takes input as string type
89
+
#int() converts it to integer type
90
+
fact =1
91
+
i =1
92
+
while i <= n:
93
+
fact = fact * i;
94
+
i = i +1
95
+
print(fact)
96
+
```
97
+
-**Using For Loop**
98
+
```python
99
+
n =int(input()) #input() function takes input as string type
100
+
#int() converts it to integer type
101
+
fact =1
102
+
for i inrange(1,n+1):
103
+
fact = fact * i
104
+
print(fact)
105
+
```
106
+
-**Using Lambda Function**
107
+
108
+
```python
109
+
# Solution by: harshraj22
110
+
111
+
n =int(input())
112
+
defshortFact(x): return1if x <=1else x*shortFact(x-1)
113
+
print(shortFact(n))
114
+
115
+
```
116
+
117
+
---
103
118
104
119
# Question 3
105
120
106
121
### **Question:**
107
122
108
-
>***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***
123
+
> **_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()***
131
+
---
132
+
133
+
### Hints:
134
+
135
+
> **_In case of input data being supplied to the question, it should be assumed to be a console input.Consider use dict()_**
118
136
119
-
-----------------
137
+
---
120
138
121
139
**Main author's Solution: Python 2**
140
+
122
141
```python
123
142
n =int(raw_input())
124
143
d =dict()
@@ -128,27 +147,31 @@ print d
128
147
```
129
148
130
149
**My Solution: Python 3:**
131
-
***Using for loop**
150
+
151
+
-**Using for loop**
152
+
132
153
```python
133
154
n =int(input())
134
155
ans = {}
135
156
for i inrange (1,n+1):
136
157
ans[i] = i * i
137
158
print(ans)
138
159
```
139
-
***Using dictionary comprehension**
160
+
161
+
-**Using dictionary comprehension**
162
+
140
163
```python
141
164
n =int(input())
142
165
ans={i : i*i for i inrange(1,n+1)}
143
166
print(ans)
144
167
```
145
-
----------------------------------
146
168
147
-
## Conclusion
148
-
***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.***
169
+
---
149
170
150
-
[***go to next day***](https://github.com/darkprinx/100-plus-Python-programming-exercises-extended/blob/master/Status/Day%202.md"Next Day")
171
+
## Conclusion
151
172
173
+
**_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._**
152
174
175
+
[**_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