Program to create a library management system using a function

In this python function program, we will create a library management system using a function.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

Steps to solve the program
  1. Create a function library.
  2. Use the def keyword to define the function.
  3. Pass two parameters i.e. book name and customers name.
  4. Print the book name and customer name.
  5. Pass the book name and customer name to the function while calling the function.
				
					def library(bname,cname):
    print("Book name: ",bname)
    print("Borrowed by :",cname)
library("Harry potter","Atharv")
				
			

Output :

				
					Book name:  Harry potter
Borrowed by : Atharv
				
			

Related Articles

program to reverse an integer.

add two Binary numbers.

Program to reverse an integer using a function

In this python function program, we will reverse an integer using a function.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

Steps to solve the program
  1. Create a function reverse.
  2. Use the def keyword to define the function.
  3. Take a number as input through the user and create a variable rev and assign its value equal to 0.
  4. Use a while loop to find the reverse of a number.
  5. While num is greater than 0 divide the number by 10 using % to find the remainder.
  6. Multiply the rev by 10 and add the remainder to it.
  7. Now divide number by 10 using //.
  8. Print the final output.
  9. Call the function to see the output.
				
					def reverse():
    num=n=int(input("Enter a number: "))
    rev=0
    while n>0:
        r=n%10
        rev=(rev*10)+r
        n=n//10
    print("Reverse number: ",rev)
reverse()
				
			

Output :

				
					Enter a number: 225
Reverse number:  522
				
			

Related Articles

check whether the given year is a leap year.

create a library management system.

Program to check whether the given year is a leap year

In this python function program, we will create a function to check whether the given year is a leap year.


Leap Year: A year, occurring once every four years, which has 366 days including 29 February as an intercalary day. A Century year is a leap year only if it is perfectly divisible by 400.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

Steps to solve the program
  1. Create a function leap.
  2. Use the def keyword to define the function.
  3. Pass a parameter i.e. year.
  4. Use the following condition to check whether the given year is a leap year or not – (year%400 == 0 or year%100 != 0) and year%4 == 0.
  5. Print the respective output.
  6. Pass the year to the function while calling the function.
				
					def leap(a):
    if (a%100!=0 or a%400==0) and a%4==0:
        print("The given year is leap year.")
    else:
        print("The given year is not leap year.")
leap(2005)
				
			

Output :

				
					The given year is not leap year.
				
			

Related Articles

create a Fruitshop Management system.

program to reverse an integer.

Python function program to create a Fruitshop Management system

In this python function program, we will create a Fruitshop Management system using function.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

Steps to solve the program
  1. Create a function fruit.
  2. Use the def keyword to define the function.
  3. Pass three parameters i.e. fruit name, fruit price, and fruit quantity.
  4. Print the fruit name, fruit price, and fruit quantity.
  5. Calculate the total bill by multiplying fruit price and fruit quantity.
  6. Print the bill.
  7. Pass the fruit name, fruit price, and fruit quantity to the function while calling the function.
				
					def fruit(fname,fprice,quantity):
    print("Fruit name: ",fname)
    print("Fruit price: ",fprice)
    print("Fruit quantity in kg: ",quantity)
    print("Bill : ",fprice*quantity)
fruit("Apple",100,2)
				
			

Output :

				
					Fruit name:  Apple
Fruit price:  100
Fruit quantity in kg:  2
Bill :  200
				
			

Related Articles

get the addition with the return statement.

check whether the given year is a leap year.

Program to get the addition with the return statement

In this python function program, we will create a function to get the addition with the return statement.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

Steps to solve the program
  1. Create a function add.
  2. Use the def keyword to define the function.
  3. Pass two parameter i.e. numbers.
  4. Get the addition of the numbers using ” + ” operator.
  5. Return the total.
  6. Pass the numbers to the function while calling the function.
				
					def add(a,b):
    total = a+b
    return total
add(5,15)
				
			

Output :

				
					20
				
			

Related Articles

print and accept login credentials.

create a Fruitshop Management system.

Python function program to print and accept login credentials

In this python function program, we will create a function to print and accept login credentials.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

Steps to solve the program
  1. Create a function login.
  2. Use the def keyword to define the function.
  3. Take name and password as input through the function.
  4. Then print Credential accepted.
  5. Call the function to print the output.
				
					def login():
    name = input("Enter name: ")
    password = input("Enter password")
    print("Credential accepted")
login()
				
			

Output :

				
					Enter name: Atharv
Enter password1234
Credential accepted
				
			

Related Articles

get a list of odd numbers from 1 to 100.

get the addition with the return statement.

Python function program to get a list of odd numbers from 1 to 100

In this python function program, we will create a function to get a list of odd numbers from 1 to 100.

Odd number:
Odd numbers are those numbers that cannot be divided into two equal parts.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

Steps to solve the program
  1. Create a function odd.
  2. Use the def keyword to define the function.
  3. Pass two parameter i.e. starting and ending numbers.
  4. Use for loop with the range function to iterate over values between 1-100.
  5. If a number is an odd number i.e. not divisible by 2 then print the number.
  6. Pass the starting and ending numbers to the function while calling the function.
				
					def odd(lower,upper):
    print("Odd numbers between", lower, "and", upper, "are:")

    for num in range(lower, upper + 1):
        if num%2 != 0:
            print(num,end=" ")
odd(1,100)
				
			

Output :

				
					Odd numbers between 1 and 100 are:
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 
49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91
93 95 97 99 
				
			

Related Articles

print a list of prime numbers from 1 to 100.

print and accept login credentials.

Program to get a list of prime numbers from 1 to 100

In this python function program, we will create a function to get a list of prime numbers from 1 to 100.

Prime Number: A prime number is a whole number greater than 1 that cannot be exactly divided by any whole number other than itself and 1.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

Steps to solve the program
  1. Create a function prime.
  2. Use the def keyword to define the function.
  3. Pass two parameters i.e. starting and ending numbers.
  4. Create a variable and assign its value equal to 0.
    If a number is divisible by 1 and by itself then it is a prime number.
  5. Use for loop with the range function to check whether a number is a prime number or not.
  6. Add only those numbers to the variable.
  7. Print the output.
  8. Pass the starting and ending numbers to the function while calling the function.
				
					def prime(lower,upper):
    print("Prime numbers between", lower, "and", upper, "are:")

    for num in range(lower, upper + 1):
        count = 0
        for i in range(1,num+1):
            if num%i == 0:
                count += 1
        if count == 2:
            print(i,end=" ")
prime(1,100)
				
			

Output :

				
					Prime numbers between 1 and 100 are:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 
				
			

Related Articles

create dictionary output from the given string.

get a list of odd numbers from 1 to 100.

Program to create dictionary output from the given string

In this python function program, we will create a function to create dictionary output from the given string.

Dictionary:
A dictionary consists of a collection of key-value pairs.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

Steps to solve the program
  1. Create a function fun.
  2. Use the def keyword to define the function.
  3. Pass a parameter i.e. string to the function.
  4. Create an empty dictionary.
  5. Create a list of the words in the string using split(” “).
  6. Use a for loop to iterate over the words in the list.
  7. Add the first letter and the last letter of the word as the key and the word as the value to the dictionary.
  8. Return the list.
  9. Pass the dictionary to the function while calling the function.
				
					def fun(string):
    a= {}
    l = string.split(" ")
    for word in l:
        a[word[0]+word[-1]] = word
    return a
fun("Python is easy li Learn")
				
			

Output :

				
					{'Pn': 'Python', 'is': 'is', 'ey': 'easy', 'li': 'li', 'Ln': 'Learn'}
				
			

Related Articles

get the square of all values in the given dictionary.

print a list of prime numbers from 1 to 100.

Python function program to get the square of all values in the given dictionary

In this python function program, we will create a function to get the square of all values in the given dictionary.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

Steps to solve the program
  1. Create a function square.
  2. Use the def keyword to define the function.
  3. Pass a parameter i.e. dictionary to the function.
  4. Create an empty dictionary.
  5. Use a for loop to iterate over the keys and values of the dictionary.
  6. Add the key the empty dictionary and sqaure of the original value as the new value.
  7. Return the new dictionary.
  8. Pass the dictionary to the function while calling the function.
				
					def square(d):
    a = {}
    for key,value in d.items():
        a[key] = value**2
    return a
square({'a':4,'b':3,'c':12,'d':6})
				
			

Output :

				
					{'a': 16, 'b': 9, 'c': 144, 'd': 36}
				
			

Related Articles

get the duplicate characters from the string.

create dictionary output from the given string.