Python Executed Programs

num1 = int(input(“Enter the first number: “))
num2 = int(input(“Enter the second number: “))
num3 = int(input(“Enter the third number: “))
if num1>num2:
if num1>num3:
print(num1, “is the largest number.”)
else:
print(num3, “is the largest number.”)
else:
if num2>num3:
print(num2, “is the largest number.”)
else:
print(num3, “is the largest number.”)

====================================================================
age=int(input(“Enter your age: “))
if age>=18:
print(“You are an adult.”)
if age>=21:
print(“You are eligible to drink alchohol.”)
else:
print(“You are not eligible to drink alcohol.”)
else:
print(“You are a minor.”)
====================================================================
age=int(input(“Enter your age: “))
if age>=18:
print(“You are an adult.”)
if age>=21:
print(“You are eligible to drink alchohol.”)
else:
print(“You are not eligible to drink alcohol.”)
else:
print(“You are a minor.”)
==================================================================
num1 = int(input(“Enter the first number: “))
num2 = int(input(“Enter the second number: “))
num3 = int(input(“Enter the third number: “))
if num1>num2:
if num1>num3:
print(num1, “is the largest number.”)
else:
print(num3, “is the largest number.”)
else:
if num2>num3:
print(num2, “is the largest number.”)
else:
print(num3, “is the largest number.”)

=================================================================
a=48
b=34
if a<b:
print(“B is big”)
print(“B value is”, b)
else:
print(“A is big”)
print(“A value is”,a)
print(“END”)
===================================================================
a=eval(input(“Enter a value:”))
if a%2==0:
print(“a is EVEN number”)
else:
print(“a is NOT EVEN Number”)
==============================================================
basic_salary=4000
sales=float(input(“Enter the total sales:”))
if sales>=100000:
hra=0.20*basic_salary
da=0.11*basic_salary
conveyance=500
incentive=0.10*sales
bonus=1000
total_salary=basic_salary+hra+da+conveyance+incentive+bonus
else:
hra=0.10*basic_salary
da=0.11*basic_salary
conveyance=500
incentive=0.04*sales
bonus=500
total_salary=basic_salary+hra+da+conveyance+incentive+bonus
print(“The total salary is”,total_salary)
=================================================================
#Assigning values too variables
name=”Wilson Ministries”
age=30
gpa=3.14
is_student=True
students=[“Rani”,”Sony”,”Rashmi”]
person={“name”:”Wilson Ministries”,”age”:30,”is_student”:True}
#Printing the variables
print(“Name:”,name)
print(“Age:”,age)
print(“GPA:”,gpa)
print(“is student:”,is_student)
print(“Students:”,students)
print(“Person:”,person)
=================================================================
#Assigning multiple values to multiple variables
name,age,gpa=”Wilson Ministries”,30,3.14
is_student,students=True,[“Rani”,”Sony”,”Ramya”]
person={“name”:”Rani”,”age”:30,”is_student”:True}
#printing the variables
print(“Name:”,name)
print(“Age:”,age)
print(“GPA:”,gpa)
print(“Is student:”,is_student)
print(“Students:”,students)
print(“Person:”,person)
=============================================================
a=10 #integer
b=12.65#floating-point number
d=2+5j#complex numbe
print(“int is”,a)
print(“float is”,b)
print(“complex is”,d)
==============================================================
a=10
b=15
if a<b:
print(“B is big”)
print(“B value is”,b)
==========================================================
from math import pi
radius=eval(input(“Enter radius of circle:”))
if radius>0:
area=radius*radius*pi
print(“Area of circle is:”,format(area,”.2f”))
circum=2*pi*radius
print(“Circumference of circle is:”,format(circum,”.2f”))
else:
print(“The radius must be greater than zero”)
================================================================
#Get the three numbers from the user
num1=int(input(“Enter the first number:”))
num2=int(input(“Enter the second number:”))
num3=int(input(“Enter the third number:”))
#Check which number is the largest
if num1>num2 and num1>num3:
print(“The first number is the largest.”)
elif num2>num1 and num2>num3:
print(“The second number is the largest.”)
else:
print(“The third number is the largest.”)
==================================================================
#Get the marks of five subjects from the user
subject1=float(input(“Enter the marks of C & DS:”))
subject2=float(input(“Enter the marks of Python:”))
subject3=float(input(“Enter the marks of Java:”))
subject4=float(input(“Enter the marks of RDBMS:”))
subject5=float(input(“Enter the marks of OS:”))
#Calculate the total marks and percentage of marks
total_marks=subject1+subject2+subject3+subject4+subject5
percentage=(total_marks/500)*100
#Display a message according to the range of the percentage
if percentage>=90:
print(“You have scored an A+ grade with”,percentage,”%”)
elif percentage>=80:
print(“You have scored an A grade with”,percentage,”%”)
if percentage>=70:
print(“You have scored a B grade with”,percentage,”%”)
if percentage>=60:
print(“You have scored a C grade with”,percentage,”%”)
if percentage>=50:
print(“You have scored a D grade with”,percentage,”%”)
else:
print(“You have failed with”,percentage,”%”)
=====================================================================
#Get the number representing the day of the week from the user
day_num=int(input(“Enter a number representing a day of the week(1-7):”))
#Display the name of the day if the number is between 1 and 7
if day_num==1:
print(“Monday”)
elif day_num==2:
print(“Tuesday”)
elif day_num==3:
print(“Wednessday”)
elif day_num==4:
print(“Thursday”)
elif day_num==5:
print(“Friday”)
elif day_num==6:
print(“Saturday”)
elif day_num==7:
print(“Sunday”)
else:
print(“Invalid day number.”)
=================================================================
#Get two numbers from the user
num1=float(input(“Enter first number:”))
num2=float(input(“Enter second number:”))
#Get the user’s choice of operation
print(“Choose an operation:”)
print(“1.Addition”)
print(“2.Subtraction”)
print(“3.Multiplication”)
print(“4.Division”)
choice=int(input(“Enter choice(1/2/3/4):”))
#Perform the selected operation
if choice==1:
result=num1+num2
print(“The result of”,num1,”+”,num2,”is”,result)
elif choice==2:
result=num1-num2
print(“The result of”,num1,”-“,num2,”is”,result)
elif choice==3:
result=num1*num2
print(“The result of”,num1,”*”,num2,”is”,result)
elif choice==4:
result=num1/num2
print(“The result of”,num1,”/”,num2,”is”,result)
else:
print(“Invalid choice.”)
===================================================================
count=1
while count<=5:
print(count)
count+=1
===================================================================
#Initialize the loop variable and the sum
i=1
sum=0
#Start the while loop
while i<=10:
sum=sum+i
i=i+1
#Print the result
print(“The sum of the first 10 consecutive numbers is:”,sum)
===================================================================
#Get the input number
number=int(input(“Enter a number:”))
sum=0
while number>0:
#Get the last digit of the number
last_digit=number%10
sum=sum+last_digit
number=number//10
#Print the result
print(“The sum of the digits is:”,sum)
====================================================================
#Get the input number
number=int(input(“Enter a number:”))
#Initialize the reverse
reverse=0
while number>0:
last_digit=number%10
reverse=reverse*10+last_digit
number=number//10
#print the result
print(“The reverse of the number is:”,reverse)
===================================================================
number=int(input(“Enter a number:”))
copy=number
sum=0
num_of_digits=0
#Get the number of digits
temp=copy
while temp>0:
num_of_digits=num_of_digits+1
temp=temp//10
while copy>0:
last_digit=copy%10
sum=sum+last_digit**num_of_digits
copy=copy//10
#Check if the sum is equal to the number
if number==sum:
print(number,”is an Armstrong number.”)
else:
print(number,”is not an Armstrong number.”)
===================================================================
number=int(input(“Enter a number:”))
factorial=1
i=1
while i<=number:
factorial=factorial*i
i=i+1
print(“The factorial of”,number,”is”,factorial)
==================================================================
n=int(input(“Enter the number up to which you want to print the Fibonacci series:”))
a,b=0,1
fibonacci=[]
for i in range(n):
fibonacci.append(a)
a,b=b,a+b
print(“Fibonacci series up to”,n,”:”,fibonacci)
==================================================================
numbers=[]
for i in range(4):
num=int(input(“Enter a number:”))
numbers.append(num)
max_num=numbers[0]
for num in numbers:
if num>max_num:
max_num=num
print(“The greatest number among”,numbers,”is”,max_num)
==================================================================
mat=[[1,2,3],[4,5,6],[7,8,9]]
for r in mat:
print(r)
m=len(mat)
n=len(mat[0])
for i in range(0,m):
print(“”)
for j in range(0,n):
print(mat[i][j],end=””)
==================================================================
matrix1=[]
matrix2=[]
# input matrix 1
rows = int(input(“Enter the number of rows for matrix 1:”))
columns = int(input(“Enter the number of columns for matrix 1:”))
print(“Enter elements of matrix 1:”)
for i in range(rows):
row=[]
for j in range(columns):
row.append(int(input(f”Enter element({i+1},{j+1}):”)))
matrix1.append(row)
#input matrix 2
rows = int(input(“Enter the number of rows for matrix 2:”))
columns = int(input(“Enter the number of columns for matrix 2:”))
print(“Enter elements of matrix 2:”)
for i in range(rows):
row=[]
for j in range(columns):
row.append(int(input(f”Enter element({i+1},{j+1}):”)))
matrix2.append(row)
#add matrices
result=[]
for i in range(len(matrix1)):
row=[]
for j in range(len(matrix1[0])):
row.append(matrix1[i][j]+matrix2[i][j])
result.append(row)
#display result
print(“Result of matrix addition:”)
for row in result:
print(row)
===================================================================
#Program to multiply two matricess using nested loops
#take input for first matrix
m1_rows=int(input(“Enter the number of rows for matrix 1:”))
m1_cols=int(input(“Enter the number of columns for matrix 1:”))
print(“Enter the elements of first matrix:”)
matrix1=[]
for i in range(m1_rows):
a=[]
for j in range(m1_cols):
a.append(int(input()))
matrix1.append(a)
#take input for second matrix
m2_rows=int(input(“Enter the number of rows for matrix 2:”))
m2_cols=int(input(“Enter the number of columns for matrix 2:”))
if m1_cols!=m2_rows:
print(“The number of columns of first matrix should be equal to the number of rows of second matrix.”)
else:
print(“Enter the elements of second matrix:”)
matrix2=[]
for i in range(m2_rows):
b=[]
for j in range(m2_cols):
b.append(int(input()))
matrix2.append(b)
#initializing the result matrix
result=[[0 for j in range(m2_cols)] for i in range(m1_rows)]
#multiplying matrices using nested loops
for i in range(m1_rows):
for j in range(m2_rows):
for k in range(m2_rows):
result[i][j]+=matrix1[i][k]*matrix2[k][j]
#printing the result
print(“The result of matrix multiplication is:”)
for i in range(m1_rows):
for j in range(m2_cols):
print(result[i][j],end=”\t”)
print()
====================================================================

FAQ:

Python coding description example
Python programming examples
What is Python used for
Features of Python
Python interview questions
Which type of programming does Python support
Introduction to Python
History of Python
2 thoughts on “Python Tutorial – కోడింగ్లో పైథాన్ ఏమి చేస్తుంది?”

Leave a Reply

Your email address will not be published. Required fields are marked *