-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython 32.py
More file actions
49 lines (29 loc) · 752 Bytes
/
Copy pathpython 32.py
File metadata and controls
49 lines (29 loc) · 752 Bytes
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
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
61. Write a program to compute 1/2+2/3+3/4+...+n/n+1 with a given n input by console (n>0).
If the following n is given as input to the program: 5
Then, the output of the program should be: 3.5
# In[ ]:
n=int(input('enter the number'))
s=0
for i in range(1,n+1):
s=s+(i/(i+1))
print(round(s,1))
# In[ ]:
62. Write a program to compute:
f(n)=f(n-1)+100 when n>0
and f(0)=1
with a given n input by console (n>0).
If the following n is given as input to the program: 5
Then, the output of the program should be: 500
# In[2]:
def f(n):
if n==0:
return 1
if n==1:
return 100
if n>1:
return (f(n-1)+100)
f(n)
f(5)