Monday, July 11, 2022

Python Function - Exercise

Practice Programs:
1. Write a python function that accepts a string and calculates the number of uppercase letter and lowercase letters:
Sample String:
Hello World
Expected Output:
No. Of Uppercase Character : 2
No of Lowercase Character: 8

2. Write a calculator function that can take two or more numbers and calculate Addition, multiplication, subtraction of these number among themselves
Example: Input: 2,3,4 
Output: addition is 9, multiplication is 24 , subtraction is -5
Input: 1,2,3,4 
Output: addition is 10, multiplication is 24 , subtraction is -8

3. Write a python program that accepts a hyphen-seperated sequence of words as input and prints the words in a hyphen-seperated sequence after sorting them alphabetically.
Example Input: green-red-yellow-black-white
Expected Output: black-green-red-white-yellow

4. Write a Python function that accepts a string and calculate the number of upper case letters and lower case letters. 
Sample String : 'The Subject IS Amazing'
Expected Output :
No. of Upper case characters : 5
No. of Lower case Characters : 14

5. What will be the output of the following code?
	def my_func(var1=100, var2=200):
       var1+=10
       var2 = var2 - 10
       return var1+var2
	print(my_func(50),my_func())
    
6. What will be the output of the following code?
    value = 50
    def display(N):
       global value
       value = 25
       if N%7==0:
       	value = value + N 
       else:
       	value = value - N 
    print(value, end="#")
    display(20)
    print(value)
7. Write a python function that takes a number and calculates cube for it. The function does not return a value , if there is no value passed to the function call, the function should calculate cube of 2.

8. Write a function that takes two char arguments and return True if both the arguments are equal otherwise False
Share: