I have written a Program that adds and multiples first ten Natural Numbers on user input. I have made two separate functions for Addition and Multiplication and called both functions in a while loop using if-else statement in it. But it is taking input from user but not performing any further operations. Code is Below:
print("Please select one of the Following Functions:")
print("1. Add First Ten Numbers")
print("2. Multiply first ten Numbers")
user=input()
plus=0
mul=1
for a2 in range(11):
if a2>0:
plus=plus + a2
mul=mul * a2
def add():
print("Sum of First Ten Numbers is",plus)
def product():
print("Product of First Ten Numbers is",mul)
while True:
if user == 1 and user !=2:
add()
elif user == 2:
product()
Output:

Aucun commentaire:
Enregistrer un commentaire