Write a python function that takes a list as an argument. Your task is to create a new list where
each element can be present at max 2 times. Inside the function, print the number of
elements removed from the given list. Finally, return the new list and print the result.
=====================================================
Hint: You may use list_name.count(element) to count the total number of times an element is in
a list. list_name is your new list for this problem.
=====================================================
Function Call:
function_name([1, 2, 3, 3, 3, 3, 4, 5, 8, 8])
Output:
Removed: 2
[1, 2, 3, 3, 4, 5, 8, 8]
================================
Function Call:
function_name([10, 10, 15, 15, 20])
Output:
Removed: 0
[10, 10, 15, 15, 20]
Write a function called rem_duplicate that takes a tuple in the parameter and return a tuple
removing all the duplicate values. Then print the returned tuple in the function call.
[Cannot use remove() or removed() for this task]
===================================================================
Hints:
Unlike lists, tuples are immutable, so the tuple taken as an argument cannot be modified. But
the list can be modified and lastly for returning the result use type conversion. You need to use
membership operators (in, not in) for preventing adding any duplicates values.
===================================================================
Example1:
Function Call:
rem_duplicate((1,1,1,2,3,4,5,6,6,6,6,4,0,0,0))
Output:
(1, 2, 3, 4, 5, 6, 0)
===================================================================
Example2:
Function Call:
rem_duplicate(("Hi", 1, 2, 3, 3, "Hi",'a', 'a', [1,2]))
Output:
('Hi', 1, 2, 3, 'a', [1, 2])
Write a function called make_square that takes a tuple in the parameter as a range of numbers
(starting point and ending point (included)). The function should return a dictionary with the
numbers as keys and its squares as values.
===================================================================
Hints:
You need to declare a dictionary to store the result. You should use the range function to run
the “for loop”.
===================================================================
Example1:
Function Call:
make_square((1,3))
Output:
{1: 1, 2: 4, 3: 9}
===================================================================
Example2:
Function Call:
make_square((5,9))
Output:
{5: 25, 6: 36, 7: 49, 8: 64, 9: 81}
Write a function called area_circumference_generator that takes a radius of a circle as a
function parameter and calculates its circumference and area. Then returns these two results as
a tuple and prints the results using tuple unpacking in the function call according to the given
format.
[Must use tuple packing & unpacking]
===================================================================
Example1:
Function Call:
area_circumference_generator(1)
Output:
(3.141592653589793, 6.283185307179586)
Area of the circle is 3.141592653589793 and circumference is 6.283185307179586
Write a function called show_palindromic_triangle that takes a number as an argument and
prints a Palindromic Triangle in the function.
[Must reuse the show_palindrome() function of the previous task]
===================================================================
Hints(1):
Need to use both print() and print( , end = " ") functions
===================================================================
Example1:
Function Call:
show_palindromic_triangle(5)
Output:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
===================================================================
Example2:
Function Call:
show_palindromic_triangle(3)
Output:
1
1 2 1
1 2 3 2 1
Write a function called show_palindrome that takes a number as an argument and then returns
a palindrome string. Finally, prints the returned value in the function call.
Example1:
Function Call:
show_palindrome(5)
Output:
123454321
===================================================================
Example2:
Function Call:
show_palindrome(3)
Output:
12321
Write a function which will take 1 argument, number of days.
Your first task is to take the number of days as user input and pass the value to the function.
Your second task is to implement the function and calculate the total number of years, number
of months, and the remaining number of days as output. No need to return any value, print
inside the function.
Note: Assume, each year to be 365 days and month to be 30 days.
Hint(1): Divide and mod the main input to get the desired output.
Hint(2): This task’s calculation is similar to Assignment-1’s seconds to hours, minutes
conversion.
Example01
Input:
4330
Function Call:
function_name(4330)
Output:
11 years, 10 months and 15 days
===================================================================
Example02
Input:
2250
Function Call:
function_name(2250)
Output:
6 years, 2 months and 0 days
Write a function called calculate_tax that takes 3 arguments: your age, salary, and current job
designation.
Your first task is to take these arguments as user input and pass these values to the function.
Your second task is to implement the function and calculate the tax as the following conditions:
NO TAX IF YOU ARE LESS THAN 18 YEARS OLD.
NO TAX IF YOU ARE THE PRESIDENT OF THE COMPANY
No tax if you get paid less than 10,000
5% tax if you get paid between 10K and 20K
10% tax if you get paid more than 20K
Write a python function that takes a string as an argument. Your task is to calculate the number
of uppercase letters and lowercase letters and print them in the function.
===================================================================
Function Call:
function_name('The quick Sand Man')
Output:
No. of Uppercase characters : 3
No. of Lowercase Characters: 12
===================================================================
Function Call:
function_name('HaRRy PotteR')
Output:
No. of Uppercase characters : 5
No. of Lowercase Characters: 6
Write a function called foo_moo that takes a number as an argument and returns the following
statements according to the below mentioned conditions. Then, finally prints the statement in
the function call.
If the number is divisible by 2, it should return "Foo".
If the number is divisible by 3, it should return "Moo".
If the number is divisible by both 2 and 3, it should return "FooMoo".
Otherwise, it returns "Boo".