DEV Community

Kuhanraja A R
Kuhanraja A R

Posted on

python session day 4 at payilagam return and input()function in python

input():
input() in Python takes input from a user and returns it as a string by default

name = input("Enter your name: ")
print("Welcome to Python", name)
print(type(name))
Enter fullscreen mode Exit fullscreen mode

Enter your name: RAJA
Welcome to Python RAJA

return statement :
return statement is used to end the execution of the function call and “returns” the result (value of the expression following the return keyword) to the caller

*Example : *

def display():
    print("hello")
display()

Enter fullscreen mode Exit fullscreen mode
output:
hello
Enter fullscreen mode Exit fullscreen mode

In this program it displays only hello as output.

*Example 2 : *

def display():
    print("hello")
print(display())
Enter fullscreen mode Exit fullscreen mode
output:
hello 
none
Enter fullscreen mode Exit fullscreen mode

In this case the function has been terminated after the print statement. no more values has returned to the function so when we asked to display the (display()) function. It gives the output as none.

example 3 :

def display():
    print("hello")
    return 10+20
print(display())
Enter fullscreen mode Exit fullscreen mode
output:
hello
30
Enter fullscreen mode Exit fullscreen mode

In this case the function is like restarted. when we asked to return some values by putting return statement it starts functioning. it displays the value as 30.

sslc mark calculator

tamil = input("Tamil Mark please: ")
english = input("English Mark please: ")
maths = input("Maths Mark please: ")
science = input("Science Mark please: ")
social = input("Social Mark please: ")
total = (int(tamil) + int(english) + int(maths) + int(science) + int(social))
print("total mark : ",total)
print('average =', (total)*(100/500))
Enter fullscreen mode Exit fullscreen mode
output:
tamil = input("Tamil Mark please: ")
english = input("English Mark please: ")
maths = input("Maths Mark please: ")
science = input("Science Mark please: ")
social = input("Social Mark please: ")
total = (int(tamil) + int(english) + int(maths) + int(science) + int(social))
print("total mark : ",total)
print('average =', (total)*(100/500))

Enter fullscreen mode Exit fullscreen mode

in this program we are getting the marks from the users and printing the total marks and calculating the percentage of the candidate.

EB bill calculator:

consumer = int(input("enter the electricity unit: "))
print("your electricity bill is:", (consumer)*(0.40))
Enter fullscreen mode Exit fullscreen mode
output:
enter the electricity unit: 100
your electricity bill is: 40.0
Enter fullscreen mode Exit fullscreen mode

*EMI calculator : *

P = int(input("Enter the principal amount : "))
N = int(input("Enter the number of months : "))
R = int(input("Enter the monthly interest rate : "))
print("YOUR EMI IS",(P*R*(1+R)**N) / ((1+R)**N-1))
Enter fullscreen mode Exit fullscreen mode
output:
Enter the principal amount : 500000
Enter the number of months : 10
Enter the monthly interest rate : 3.5
YOUR EMI IS 1750000.5139407318
Enter fullscreen mode Exit fullscreen mode

BMI CALCULATOR :

weight = float(input("enter your weight in kgs : ")
height = float(input("enter your height : )
print("YOUR BMI IS : ", weight/h(height**2))
Enter fullscreen mode Exit fullscreen mode
output:
enter your weight in kgs : 104
enter your height : 1.73
YOUR BMI IS :  34.74890574359317

Enter fullscreen mode Exit fullscreen mode

Top comments (0)