Python Programs
Python Programs
Output
Enter first number: 5
Enter second number: 6
The sum of two numbers 11
x=5
y = 10
temp = x
x=y
y = temp
Output
The value of x after swapping: 10
The value of y after swapping: 5
Output
The largest number is 14.0
Output
29 is a prime number
if num < 0:
print("factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
Output
if nterms <= 0:
print("Please enter a positive integer")
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1)
else:
print("Fibonacci sequence:")
while count < nterms:
print(n1)
nth = n1 + n2
n1 = n2
n2 = nth
count += 1
Output
How many terms? 7
Fibonacci sequence:
0
1
1
2
3
5
8