0% found this document useful (0 votes)
26 views3 pages

Python Pro

The document contains multiple Python programs that demonstrate various functionalities, including exchanging values of two numbers, checking if a number is positive or negative, calculating grades based on marks, finding numbers divisible by a given number, generating combinations of distinct digits, summing digits, counting digits, finding the largest number in a list, separating even and odd numbers, and performing basic arithmetic operations. Each program includes user input prompts and outputs the results accordingly. The document serves as a collection of coding examples for basic programming concepts in Python.

Uploaded by

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

Python Pro

The document contains multiple Python programs that demonstrate various functionalities, including exchanging values of two numbers, checking if a number is positive or negative, calculating grades based on marks, finding numbers divisible by a given number, generating combinations of distinct digits, summing digits, counting digits, finding the largest number in a list, separating even and odd numbers, and performing basic arithmetic operations. Each program includes user input prompts and outputs the results accordingly. The document serves as a collection of coding examples for basic programming concepts in Python.

Uploaded by

smishra
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

This is a Python Program to exchange the values of two numbers without using a temporary

variable.

a=int(input("Enter value of first variable: "))


b=int(input("Enter value of second variable: "))
a=a+b
b=a-b
a=a-b
print("a is:",a," b is:",b)

This is a Python Program to check whether a number is positive or negative.

n=int(input("Enter number: "))


if(n>0):
print("Number is positive")
else:
print("Number is negative")

This is a Python Program to take in the marks of 5 subjects and display the grade.

sub1=int(input("Enter marks of the first subject: "))


sub2=int(input("Enter marks of the second subject: "))
sub3=int(input("Enter marks of the third subject: "))
sub4=int(input("Enter marks of the fourth subject: "))
sub5=int(input("Enter marks of the fifth subject: "))
avg=(sub1+sub2+sub3+sub4+sub4)/5
if(avg>=90):
print("Grade: A")
elif(avg>=80&avg<90):
print("Grade: B")
elif(avg>=70&avg<80):
print("Grade: C")
elif(avg>=60&avg<70):
print("Grade: D")
else:
print("Grade: F")

This is a Python Program to print all numbers in a range divisible by a given number.

lower=int(input("Enter lower range limit:"))


upper=int(input("Enter upper range limit:"))
n=int(input("Enter the number to be divided by:"))
for i in range(lower,upper+1):
if(i%n==0):
print(i)

This is a Python Program to accept three distinct digits and print all possible combinations from
the digits.
a=int(input("Enter first number:"))
b=int(input("Enter second number:"))
c=int(input("Enter third number:"))
d=[]
[Link](a)
[Link](b)
[Link](c)
for i in range(0,3):
for j in range(0,3):
for k in range(0,3):
if(i!=j&j!=k&k!=i):
print(d[i],d[j],d[k])

This is a Python Program to find the sum of digits in a number.

n=int(input("Enter a number:"))
tot=0
while(n>0):
dig=n%10
tot=tot+dig
n=n//10
print("The total sum of digits is:",tot)

This is a Python Program to count the number of digits in a number.

n=int(input("Enter number:"))
count=0
while(n>0):
count=count+1
n=n//10
print("The number of digits in the number are:",count)

This is a Python Program to find the largest number in a list.

a=[]
n=int(input("Enter number of elements:"))
for i in range(1,n+1):
b=int(input("Enter element:"))
[Link](b)
[Link]()
print("Largest element is:",a[n-1])

This is a Python Program to put the even and odd elements in a list into two different lists.
a=[]
n=int(input("Enter number of elements:"))
for i in range(1,n+1):
b=int(input("Enter element:"))
[Link](b)
even=[]
odd=[]
for j in a:
if(j%2==0):
[Link](j)
else:
[Link](j)
print("The even list",even)
print("The odd list",odd)

This is a Python Program to check whether a number is positive or negative.

n=int(input("Enter number: "))


if(n>0):
print("Number is positive")
else:
print("Number is negative")

This is a Python Program to check whether a number is positive or negative.

n=int(input("Enter number: "))


if(n%==0):
print("Number is Even")
else:
print("Number is Odd")

This is a Python Program to perform arithmetic operations.

N1=int(input("Enter number: "))


N2=int(input("Enter number: "))
print("Sum of Numbers is ", N1+N2)
print("Sub of Numbers is ", N1-N2)
print("Division of Numbers is ", N1/N2)
print("Multiplication of Numbers is ", N1*N2)

You might also like