Niranjanlab 4 Work
Niranjanlab 4 Work
Techspire College
CT108-3-1
Python Programming
Lab Report
6 FUNCTION IN PYTHON
Part A
def evenodd(num):
if num %2 ==0:
print("even")
else:
print("odd")
def function(marks):
if marks>50:
print("you passed")
else:
print("you failed")
result = function(60)
3. Write a PYTHON program to find largest of three numbers
4. def function(num1,num2,num3):
5. if num1>num2 and num1>num3:
6. print("largest: ", num1)
7.
8. elif num2>num3 and num2>num1:
9. print("largest: ",num2)
10.
11. else:
12. print("largest: ", num3)
13.
14. result = function(5,3,8)
4. Write a program to display profit or loss in trading of an item.
Sample input/output:
Enter selling price: 20
Enter buying price:19
You have profit in trading of this item
def function(SP,CP):
if SP>CP:
print("you have profit in trading of this item")
else:
print(" you have loss in trading of this item")
result = function(20,19)
Part B
1. . Lecturers often provide scores on tests, which are converted to grades the end of the semester.
Write a python program to ask for the score input and print the respective grade as follow:
2. def function(score):
3. if score>=80:
4. return 'A'
5.
6. elif score>=60 and score<=79:
7. return 'B'
8.
9. elif score>= 40 and score<=59:
10. return 'C'
11. else:
12. return 'D'
13.
14. score = int(input("enter your score: "))
15.
16. result = function(score)
17. print("your grade is " , result)
2. Write a PYTHON program to find smallest of three numbers
def function(num1,num2,num3):
if num1<num2 and num1<num3:
print("smallest: ", num1)
else:
print("smallest: ", num3)
3. Write a PYTHON program to check a year is a leap year or not a leap year.
def function(days):
if days == 366:
return 'leaf year'
else:
return 'not leaf year'
4. Write a Python program to determine whether the speed limit exceeds 110 km per hour. If
the speed exceeds 110, then fine = 300, otherwise fine = 0. Display fine.
def function(speed):
if speed == 110:
return 'fine is 300'
else:
return 'fine is 0'
def function(age):
if age >= 18:
return 'ticket is 20'
else:
return 'ticket is 10'
vovel = 'aeiouAEIOU'
def function(letter):
if letter in vovel:
return 'vovel'
else:
return 'consonent'
result = function(letter)
print(result)
7. A company insures its drivers in the following cases: - If the driver is married. - If the
driver is unmarried, male and above 30 years of age. - If the driver is unmarried, female and above
25 years of age. In all the other cases, the driver is not insured. If the marital status, gender, and age
of the driver are the inputs.
else:
return ' not insured'
result = insure_or_not(gender,age,maritalstatus)
print(result)