0% found this document useful (0 votes)
5 views

Python Programmes

The document contains a series of Python programs that demonstrate various functionalities including arithmetic and relational operations, calculation of simple interest, sum and average of numbers, finding the greatest of three numbers, summing natural numbers, printing patterns, and generating Fibonacci series. Each program includes code snippets and sample outputs to illustrate their functionality. The programs are designed for educational purposes to help users understand basic programming concepts in Python.

Uploaded by

kd060094
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Python Programmes

The document contains a series of Python programs that demonstrate various functionalities including arithmetic and relational operations, calculation of simple interest, sum and average of numbers, finding the greatest of three numbers, summing natural numbers, printing patterns, and generating Fibonacci series. Each program includes code snippets and sample outputs to illustrate their functionality. The programs are designed for educational purposes to help users understand basic programming concepts in Python.

Uploaded by

kd060094
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Python Programs Assignment

Program 1:
Code:
#Python code to use arithmetical and relational operators
a=float(input("Enter the first number"))#Asking for the first number
b=float(input("Enter the second number"))#Asking for the second
number
c=input('''Enter 1 to use arithmetical operations
Enter 2 to use relational operations''')#Asking for the type of operation
to be used
if c=="1":#Using arithmetical operations
print("The sum of the two numbers is",a+b)#Sum of the two numbers
print("The difference between the two numbers is",a-b)#Difference
of the two numbers
print("The product of the two numbers is",a*b)#Product of the two
numbers
print("The divide of the two numbers is",a/b)#Divide of the two
numbers
print("The remainder after division of the two numbers is",a%b)
#Remainder after division of the two numbers
if c=="2":#Using relational operations
print("The greater of the two numbers is",max(a,b))#Maximum of the
two numbers
print("The smaller of the two numbers is",min(a,b))#Minimum of the
two numbers
if a==b:#Checking if the numbers are equal
print("Both the numbers are equal")#Printing that the numbers are
equal
else:#If the numbers would not be equal, they would be unequal
print("The numbers are not equal")#Printing that the numbers are
unequal
Output 1:
Enter the first number56
Enter the second number67
Enter 1 to use arithmetical operations
Enter 2 to use relational operations1
The sum of the two numbers is 123.0
The difference between the two numbers is -11.0
The product of the two numbers is 3752.0
The divide of the two numbers is 0.835820895522388
The remainder after division of the two numbers is 56.0

Output 2:
Enter the first number56
Enter the second number67
Enter 1 to use arithmetical operations
Enter 2 to use relational operations2
The greater of the two numbers is 67.0
The smaller of the two numbers is 56.0
The numbers are not equal

Program 2:
Code:
#Python code to find Simple Interest when Principle, Rate and Time are
given
print("This program calculates the Simple Interest")#Telling the
function of the program
a=float(input("Enter the Time"))#Asking the Time
b=float(input("Enter the Principle"))#Asking the Principle
c=float(input("Enter the Rate of Interest"))#Asking the Rate of Interest
print("Your Simple Interest is",a*b*c/100)#Calculating and printing the
Simple Interest
Output:
This program calculates the Simple Interest
Enter the Time6.89
Enter the Principle38932.238
Enter the Rate of Interest5.89
Your Simple Interest is 15799.519757397997

Program 3:
Code:
#Program to calculate the sum and average of three numbers
#Asking numbers from the user
a=float(input("Enter the first number: "))
b=float(input("Enter the second number: "))
c=float(input("Enter the third number: "))
# Calculating the sum
d=a+b+c
# Calculating the average
e=d/3
# Displaying the results
print("The sum of the three numbers is:",d)
print("The average of the three numbers is:",e)

Output:
Enter the first number: 23
Enter the second number: 34.67
Enter the third number: 345.889
The sum of the three numbers is: 403.559
The average of the three numbers is: 134.51966666666667

Program 4:
Code:
#Python program to find the greatest of three numbers
#Asking the user for the numbers
a=float(input("Enter the first number: "))
b=float(input("Enter the second number: "))
c=float(input("Enter the third number: "))
#Printing the greatest number
print("The greatest number is:",max(a,b,c))

Output:
Enter the first number: 56
Enter the second number: 67
Enter the third number: 78
The greatest number is: 78.0

Program 5:
Code:
# Calculate the sum of the first 10 natural numbers
n=10
a=sum(range(1, n + 1))
# Print the result
print("The sum of the first", n, "natural numbers is:",a)

Output:
The sum of the first 10 natural numbers is: 55

Program 6:
Code:
# Number of rows
n=4
# Loop through rows
for i in range(1, n + 1):
# Print '1' i times
print('1 ' * i)

Output:
1
11
111
1111

Program 7:
Code:
n=int(input("Enter a number"))#Number of terms in the series
a, b = 0, 1#First two terms of Fibonacci series
print(a, b, end=' ')#Printing format
for i in range(2, n):
c = a + b#Next value
print(c, end=' ')
a, b = b,c#Changing values

Output:
Enter a number9
0 1 1 2 3 5 8 13 21

You might also like