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

Python Coding 2

Fdhjrd

Uploaded by

nagaranush880
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)
9 views

Python Coding 2

Fdhjrd

Uploaded by

nagaranush880
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
You are on page 1/ 18

Q.write a programing for a leap year.

year=int(input("enter a year"))
if(year%4==0 and year%100!=0)or(year5400==0):
print(year,"is a leap year")
else:
print(year,"is not a leap year")
Input:

Output:
Q.write a program to perform arithmetic operations.
num1=int(input("enter the first number:"))
num2=int(input("enter the second number:"))
add=num1+num2
sub=num1-num2
mul=num1*num2
div=num1/num2
mod=num1%num2
expo=num1**num2
print("the sum
of{0}and{1}={2}".format(num1,num2,add))
print("the subtraction
of{0}and{1}={2}".format(num1,num2,sub))
print("the multiplication
of{0}and{1}={2}".format(num1,num2,mul))
print("the division
of{0}and{1}={2}".format(num1,num2,div))
print("the modulus
of{0}and{1}={2}".format(num1,num2,mod))
print("the exponent
of{0}and{1}={2}".format(num1,num2,expo))
input:

Output:
Q.write a program to add a element in a list.
grocery=['red sauce','salt','sugar']
grocery.append("fruit jam")
print(grocery)
Input:

Output:
Q.Write a program to delete an element from a
list.
sub=['english','hindi','french','math','science']
sub_drop=sub.pop(-4)
print("deleted subject:",sub_drop)
print("updated list:",sub)
Input:

Output:
Q.input a welcome message and display it.
message=input("enter welcome message:")
print("hello,",message)
Input:

Output:
Q.input two numbers and display the larger/smaller
number.
num1=int(input("enter the first number:"))
num2=int(input("enter the second number:"))
if(num1>num2):
print("the larger number is:",num1)
else:
print("the larger number is:",num2)
Input:

Output:
Q.Write a program to find factorial of the entered
number.
num=int(input("enter a number:"))
factorial=1
if num<0:
print("factorial does not exist")
elif num==0:
print("the factorial is 1")
else:
for i in range(1,num+1):
factorial=factorial*i
print("the factorial of",num,"is",factorial)
Input:

Output:
Q.Write a program to print Fibonacci series.
num=10
n1,n2=0,1
print("fibonacci series:",n1,n2,end="")
for i in range(2,num):
n3=n1+n2
n1=n2
n2=n3
print(n3,end="")
print()
Input:

Output:
Q.input a number and check if the number is a prime
or composite number python program.
num=int(input("enter any number:"))
if num>1:
for i in range(2,num):
if(num%i)==0:
print(num,"is not a prime number,it is a
composite number")
break
else:
print(num,"is a prime number")
elif num==0 or 1:
print(num,"is a neither prime nor composite
number")
else:
print()
Input:

Output:

You might also like