In Python WAP to input any positive integer N. If N is even, then find the sum of squares of first N natural numbers If N is odd, then find the sum of cubes of first N natural numbers
Answers
Answered by
0
Answer:
num = int(input("Enter the value of n: "))
hold = num
sum = 0
if num <= 0:
print("Enter a whole positive number!")
else:
while num > 0:
sum = sum + num
num = num - 1;
# displaying output
print("Sum of first", hold, "natural numbers is: ", sum)
Output 1:
Enter the value of n: 6
Sum of first 6 natural numbers is: 21
Output 2:
Enter the value of n: 0
Enter a whole positive number!
Output 3:
Enter the value of n: -10
Enter a whole positive number!
Output 4:
Enter the value of n: 20
Sum of first 20 natural numbers is: 210
BE THE BRAINLEST ANSWERE
Answered by
1
Answer:
..............................................
Similar questions
Computer Science,
4 months ago
History,
4 months ago
Economy,
4 months ago
Math,
9 months ago
History,
1 year ago