In a class ,'N' students are asked to bring a number of dishes as per their roll numbers, for instance ,roll number 1 will bring 1 item, roll number 2 brings 2 items and so on. Write a python function calculate(N) which takes an integer value N and returns the total number of items brought by 'N' students. Do not use input() function for taking input from keyboard. Specify it in fixed form but function must be generalized. If you enter a negative number it should print (Enter a positive number) .
def number_dishes(n):
if n<0:
return 'Enter a positive number'
else:
return (n*(n+1))//2
n = 5
print(number_dishes(n))
Comments
Leave a comment