NiranjanLab3work
NiranjanLab3work
Techspire College
CT108-3-1
Python Programming
Lab Report
6 FUNCTION IN PYTHON
2. Write a program to get an input word from a user. Then, display the given word together with
the sentence of “Welcome, ” as below:
name = input("enter your name: ")
print(" welcome ",name)
3. Write a program to get two inputs from user. Then display the input.
age = int(input("enter your age: "))
print("welcome",name)
print(f"you are {age} years old")
Part B :
1. Accept number from user and display it
#Question NO 1
def function(num):
return num
#input
num = int(input("enter a number :"))
#recall
display = function(num)
print(f" the number is {display}")
2. Accept 2 numbers from user and display addition of it.
#Question NO 2
def fuction(num2,num3):
result= num2+num3
return result
#input
#recall
final_result = fuction(num2,num3)
print(f"the addition of {num2} and {num3} is {final_result}")
3. Accept 2 input values from user and do arithmetic operation. (+, -, *, /, %).
#input
num1 = int((input("enter a number : ")))
num2 = int((input("enter a number: ")))
operand = input(" +, -, *, /, %: ")
#recall
result = function(num1,num2,operand)
print(f"The {operand } of {num1} and {num2} is {result} ")
4. Accept 2 numbers from user and print swapping of those number.
5. #Question NO 4
6.
7. def function(num1,num2):
8. num1,num2= num2,num1
9. return num1,num2
10.
11. #input
12. num1= int(input(" enter a number for num1 : "))
13. num2 = int(input("enter a number for num2 : "))
14.
15. print("********************************************After swapping
************************")
16. #recall
17.
18. num1, num2 = function(num1,num2)
19. print(f"The value of num1 is {num1} and num2 is {num2} ")
5.Accept 5 subject marks from student and calculate the total and percentage(average) of a student for a
semester and display it.
def function(sub1,sub2,sub3,sub4,sub5):
total= sub1 + sub2 + sub3 + sub4 + sub5
avg = total/5
return total,avg
#input
sub1= int(input("enter your 1st subject marks : "))
sub2= int(input("enter your 2nd subject marks : "))
sub3= int(input("enter your 3rd subject marks : "))
sub4= int(input("enter your 4th subject marks : "))
sub5= int(input("enter your 5th subject marks : "))
#recall
result_total= function(sub1,sub2,sub3,sub4,sub5)
result_avg = function(sub1,sub2,sub3,sub4,sub5)
print(f"the total of 5 subjects marks is {result_total} and average is
{result_avg}")
6. Accept Basic from an employee and calculate salary of an employee by considering following things.
(Grade_pay is double of Basic. DA is 70% of Basic. TA is RM 200. HRA is 20% of Basic.)(Formula
for salary = Grade_pay + DA + TA + HRA).
#Question no 6
def function(basic ):
Grade_pay = 2*basic
DA= 0.7*basic
TA = 200
HRA = 0.2*basic
salary = Grade_pay+ DA + TA + HRA
return salary
#input
#recall
final_salary = function(basic)