Python_Functions

def function_display_details(person_name, number):
a = 1
while (a <= number):
print(f"Hello, {person_name}")
a = a + 1
else:
print(f"I have printed {person_name} {number} times")

function_display_details("Tvisha", 2)
function_display_details("Tejasvi", 3)
function_display_details("Damodar", 4)
function_display_details("Vijaya", 5)

#______________________________________________________________________________________________________________________

#Ex: Write a function to
1. display number as long as it is less than value of 10.
2. Use the While loop and without any built-in functions like range().
3. Write the numbers in the format - 1, 2, 3, 4, 5, 6, 7, 8, 9,10

def display_number(number):
a = 1
while (a <= number):
print(a, end+",")
a = a + 1
else:
print("Loop completed")

display_number(10):

________________________________________________________________________________________________________________________

write a function to check whether the given number is even or odd?

def even_odd(num):
if num%2 == 0:
print(num,'is even number')
else:
print(num,'is odd number')

even_odd(30)
even_odd(35)

________________________________________________________________________________________________________________________

write a function to add the two numbers and return the results?

def add(x,y):
return x+y

result = add(10,20)
print('The sum is:',result)
print('The sum is:',add(20,30))

________________________________________________________________________________________________________________________

write a function to add and subtraction the two numbers and return the results?

def addition(a,b):
sum = a+b
return sum

def subtraction(a,b):
sub = a-b
return sub

def sum_sub(a,b):
sum = a+b
sub = a-b
return sum,sub

x = addition(100,50)
print('The sum is:',x)

y = subtraction(100,50)
print("The sub is:",y)

x,y = sum_sub(100,50)

print('The sum is:',x)
print("The sub is:",y)

________________________________________________________________________________________________________________________

write a function to Addition, subtraction, division and multiplication of the two numbers and return the results?

write a function to add and subtraction the two numbers and return the results?

def addition(a,b):
sum = a+b
return sum

def subtraction(a,b):
sub = a-b
return sub

def division(a,b):
div = a/b
return div

def multiplication(a,b):
mul = a*b
return mul


def calc(a,b):
sum = a+b
sub = a-b
mul = a*b
div = a/b
return sum,sub,mul,div

result = addition(100,50)
print('The sum is:',result)

result = subtraction(100,50)
print("The sub is:",result)

result = division(100,50)
print("The division is:",result)

result = multiplication(100,50)
print("The multiplication is:",result)

sum,sub,mul,div = calc(50,10)
print('The Addition is:',sum)
print("The Subtraction is:",sub)
print("The Multiplication is:",mul)
print("The Division is:",div)

________________________________________________________________________________________________________________________

write a function to find factorial of given number to the above program

def fact(num):
result = 1
while num >= 1:
result *= num
num -= 1
return result

for i in range(1,6):
print('The factorial of',i,'is:',fact(i))

________________________________________________________________________________________________________________________

# write a program to find the leap years between 2000 and 2100 years.
Use the Function and While loop and without any built-in functions like range().

def display_leap_years(start_year, end_year):
while (start_year <= end_year):
if( start_year %4 ==0 and start_year%100 == 0):
print(start_year, " is a Leap Year")
start_year=start_year+1
else:
print('Loop completed')

display_leap_years(2000, 2100)

________________________________________________________________________________________________________________________
#Ex: Python program to print a multiplication table of a given number.
Use the function for both for and while loops and without any built-in functions like range().


def display_multiplication_table_while_loop(given_number):
given_number = int(given_number)
while (start_num <= end_num):
result = given_number * start_num
print (given_number," X ", start_num , " =" , result)
start_num = start_num +1
else:
print('While Loop completed')

def display_multiplication_table_for_loop(given_number):
given_number = int(given_number)
for a in range(1, 11):
result = given_number * a
print (given_number," X ", a , " =" , result)
else:
print('For Loop completed')

display_multiplication_table_while_loop(3)
display_multiplication_table_for_loop(5)

________________________________________________________________________________________________________________________

Comments

Popular posts from this blog

clinical_app

Workplace Backstabbing False Story Defense Kit

Python_While_Loop