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.

Program to get the duplicate characters from the string

In this python function program, we will create a function to get the duplicate characters from the string.

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 dupli.
  2. Use the def keyword to define the function.
  3. Pass a parameter i.e. string to the function.
  4. Create an empty list.
  5. Use a for loop to iterate over characters from the string.
  6. Check whether the character appears in the string more than once using count().
  7. If yes then add it to the empty list.
  8. Create a set of that list using set().
  9. Print the output.
  10. Pass the string to the function while calling the function.
				
					def dupli(string):
    list1 = []
    for char in string:
        if string.count(char) > 1:
            list1.append(char)
    print(set(list1))
dupli('Programming')
				
			

Output :

				
					{'g', 'm', 'r'}
				
			

Related Articles

get unique values from the given list.

get the square of all values in the given dictionary.

Python function program to get unique values from the given list

In this python function program, we will create a function to get unique values from the given list.

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 unique.
  2. Use the def keyword to define the function.
  3. Pass a parameter i.e. list to the function.
  4. Convert the list to a set to get the unique value using set().
  5. Convert the set into a list using list()
  6. Print the output.
  7. Pass the list to the function while calling the function.
				
					def unique(l):
    distinct = set(l)
    print(list(distinct))
unique([4, 6, 1, 7, 6, 1, 5])
				
			

Output :

				
					[1, 4, 5, 6, 7]
				
			

Related Articles

check whether a combination of two numbers has a sum of 10 from the given list.

get the duplicate characters from the string.

Check whether a combination of two numbers has a sum of 10 from the given list

In this python function program, we will create a function to check whether a combination of two numbers has a sum of 10 from the given list.

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 check_sum.
  2. Use the def keyword to define the function.
  3. Pass two parameters i.e. list and the sum number to the function.
  4. Use a for loop with the range function to iterate over the elements in the list.
  5. Use a nested for loop with the range function to iterate over the next numbers from the list i.e first loop un the first iteration will use the first element and with the help of the nested loop we will iterate over the number the numbers from the second element.
  6. Now check whether the sum of 1st element and any others elements from the nested loop is equal to 10.
  7. If yes then return True else return False.
  8. Pass the list and the sum number to the function while calling the function.
				
					def check_sum(nums, k):   
    for i in range(len(nums)):
        for j in range(i+1, len(nums)):
            if nums[i] + nums[j] == k:
                return True
    return False
print(check_sum([2, 5, 6, 4, 7, 3, 8, 9, 1], 10))
				
			

Output :

				
					True
				
			

Related Articles

get the Fibonacci series up to the given number.

get unique values from the given list.