Questions:1) Define a recursive procedure in Python and in Prolog to find the sum of 1st n terms of an equal-interval seriesgiven the 1st term and the interval.2) Define a recursive procedure in Python and in Prolog to find the length of a path between two vertices of adirected weighted graph.3) Modify the Python and Prolog codes demonstrated above to find h2 and h3 discussed above.Solution to the
...[Show More]
Questions:
1) Define a recursive procedure in Python and in Prolog to find the sum of 1st n terms of an equal-interval series
given the 1st term and the interval.
2) Define a recursive procedure in Python and in Prolog to find the length of a path between two vertices of a
directed weighted graph.
3) Modify the Python and Prolog codes demonstrated above to find h2 and h3 discussed above.
Solution to the question no 1
Using python
def ssum(N,I,F):
if (N==0):
return 0
elif (N>=1):
return ssum(N-1,I,F)+F+(N-1)*I
# Main
t=int(input('How many times?'))
for i in range(t):
print('Iteration:',i+1)
f=int(input('First element:'))
d=int(input('Interval:'))
n=int(input('n:'))
print('Series sum:', ssum(n,d,f))
[Show Less]