Answer to Question #289267 in Python for rahul

Question #289267

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) .

1
Expert's answer
2022-01-23T10:37:09-0500
def number_dishes(n):
    if n<0:
        return 'Enter a positive number'
    else:
        return (n*(n+1))//2


n = 5
print(number_dishes(n))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS