technical skills grow

Responsive Ads Here

Friday, May 23, 2025

Python : Function practice question step by step


1.Write a function that checks if a number is even or odd 

def validate_no(n):
    if n % 2 == 0:
        print("Even")
    else:
        print("Odd No")
       
while True:
    no= int(input("Enter your no for validate Even or Odd No: "))
    validate_no(no)

    choose = input("Do you want Continue Y/N ")
    if choose.lower() !='y':
        break

Q2:Write a function that takes a list and returns the largest number.

def find_largest(data):
    largest =list[0]  # this line take one value and compare with list
    for num in list:
        if num > largest:
            largest=num  #This line will update largest values
    print(f"Largest No : {largest}")

list = [1,30,40,3,3,55,66]

find_largest(list)

Advance :
Q2:Write a function that takes a list and returns the largest number.
def find_largest(data):
    largest =list[0]  # this line take one value and compare with list
    for num in list:
        if num > largest:
            largest=num  #This line will update largest values
    print(f"Largest No : {largest}")

total_no = int(input("Enter your list length: "))
list =[]

for i in range(total_no):

    user_input =int(input("Enter the value in list: "))
    list.append(user_input)

find_largest(list)

Output:
Enter your list length: 5 Enter the value in list: 23 Enter the value in list: 22 Enter the value in list: 11 Enter the value in list: 44 Enter the value in list: 44 Largest No : 44

No comments:

Post a Comment

Powered by Blogger.

Labels

Contact Form

Name

Email *

Message *

Search This Blog

Blog Archive

Ad Code

Responsive Advertisement

Recent Posts