Wednesday, 14 December 2016

To convert Fahrenheit into Celsius or vice versa

print("enter choice 'c' to convert  fahrenheit  to Celsius")
print("enter choice 'f' to  convert Celsius  to  fahrenheit ")


#to accept choice of user
ch=input('enter choice(c/f):')

#to accept temperature from user
t=float(input('enter temperature:'))


if ch=='c':
    #to convert  fahrenheit  into Celsius
    cel = (t-32)*5/9
    print(' fahrenheit :',t,'\n','Celsius:',cel)
elif ch=='f':
    #to convert Celsius into  fahrenheit
    far=(t*9/5)+32
    print('Celsius:',t,'\n',' fahrenheit :',far)
else:
    #if choice is other than 'c' or 'f' display invalid choice
    print("invalid choice")


OUTPUT :

Monday, 12 December 2016

Class to find out fibonacci series,table of number,pyramid


#define class
class ftp:

    #define function to find out fibonacci series
    def fib(self,n):
        self.a=0
        self.b=1
        print("fib series=",1,' ',end='')
        for i in range(1,n):
            self.s=self.a+self.b
            print(self.s,' ',end='')
            self.a=self.b
            self.b=self.s


    #define function to find out table of number
    def table(self,n):
        print("\n""table of",n)
        for i in range(1,11):
            print(n*i)

    #define function to display pyramid
    def py(self,n):
        print("Pyramid")
        for i in range(0,n+1):
            self.s=' '*(n-i)
            self.s=self.s+ '*'*(i*2-1)
            print (self.s)
ftp=ftp()  
n=int(input("enter number:"))
ftp.fib(n)
ftp.table(n)
ftp.py(n)


OUTPUT:

Sunday, 11 December 2016

To find the reverse of number

#To find the reverse of number

#to accept the number from user
n=int(input('enter number:'))

#to store reverse of number
rev=0

#using while loop to find reverse of number
while(n!=0):
    r=n%10
    n=n//10
    rev=rev*10+r
   

#To display reverse of number
print('the reverse of number :',rev)


OUTPUT:





Monday, 5 December 2016

To check the year is leap year or not


# To check the year is leap year or not

#to accept year
y=int(input('enter year'))

#giving condition in while loop
while(y%4==0):
    print( y , 'is leap year')
    break
else:
    print( y , 'is not a leap year')



Sunday, 4 December 2016

Factors/Divisors of number

#Divisors of number/Factors of number
#Divisor/factor of an integer n, is an integer that can be multiplied by some other integer to produce n. 

#accepting number from user
n=int(input('enter no:'))

#each number is divisible by 1 as well as by itself.
print("1 &", n , ' are factor of ' , n)

#to display other divisors/factors
for i in range(2,n):
    if(n%i==0):
        print(i , ' , ' ,end='')
print(' are factors of ', n)

OUTPUT:



Table of number...


#table of number

#accepting number from user
n=int(input("enter no:"))

print("table of",n,":")

for i in range(1,11):
    print(n*i,'',end=',')

OUTPUT:

factorial of number



#factorial of number

#In mathematics, the factorial of a non-negative integer n, denoted by n!.
#It is the product of all positive integers less than or equal to n.

#to accept number from user
n=int(input('enter no:'))

#initiating variable
fact=1

#defining conditions
if(n<0):
    print('factorial of no. cannot be calculated')
elif(n==0):
    print("factorial of 0 is 1")
else:
    for i in range(1,n+1):
        fact=fact*i
    print('The factorial of', n , 'is' ,fact)

OUTPUT: