Uploaded by Sherril Sophie Maria Vincent

Basic Python Programs solutions

advertisement
Basic Python Programs
1.
2.
3.
4.
5.
6.
7.
8.
Python program to add two numbers
Maximum of two numbers in Python
Python Program to Find the Largest Among Three Numbers
Python Program for simple interest
Python Program for compound interest
Python Program for Program to find area of a circle
Python Program to check if a Number is odd or even
Python Program to Check if a Number is Positive, Negative or 0
Print Hello world
print('Hello, world!')
# This program adds two numbers
num1 = 1.5
num2 = 6.3
# Add two numbers
sum = num1 + num2
# Display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
a=2
b=4
if a >= b:
print (a)
else:
print (b)
Simple Interest
si = (p * t * r)/100
Compound Interest
A = P(1 + R/100) t
Compound Interest = A – P
Area of a circle
Area of Circle = π * R * R.
Even or ODD
num = int(input("Enter a number: "))
if (num % 2) == 0:
print("{0} is Even".format(num))
else:
print("{0} is Odd".format(num))
num1 = 10
num2 = 14
num3 = 12
# uncomment following lines to take three numbers from user
#num1 = float(input("Enter first number: "))
#num2 = float(input("Enter second number: "))
#num3 = float(input("Enter third number: "))
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
print("The largest number is", largest)
Positive, Negative or Zero
num = int(input("Input a number: "))
if num > 0:
print("It is positive number")
elif num == 0:
print("It is Zero")
else:
print("It is a negative number")
1.
2.
3.
4.
5.
6.
7.
if((Year % 400 == 0) or
(Year % 100 != 0) and
(Year % 4 == 0)):
print("Given Year is a leap Year");
# Else it is not a leap year
else:
print ("Given Year is not a leap Year")
Download