Sum or Product
Level EASY
Write a program that asks the user for a number N and a choice C. And then give them the possibility to choose between computing the sum and computing the product of all integers in the range 1 to N (both inclusive).
If C is equal to -
Input format :
Output Format :
Constraints :
Sample Input 1 :
Sample Output 1 :
Sample Input 2 :
Sample Output 2 :
Sample Input 3 :
Sample Output 3 :
-1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num=int(input()) | |
c=int(input()) | |
if c==1: | |
res=0 | |
for i in range(1,num+1): | |
res=res+num | |
num=num-1 | |
print(res) | |
elif c==2: | |
res=1 | |
for i in range(1,num+1): | |
res=res*num | |
num=num-1 | |
print(res) | |
else:print(-1) |
Comments
Post a Comment
Please give us your valuable feedback