Professional Documents
Culture Documents
1. Write a Python program to find whether a given array of integers contains any duplicate element. Return
true if any value appears at least twice in the said array and return false if every element is distinct
Answer Code:-
def test_duplicate(array_nums):
nums_set = set(array_nums)
print(test_duplicate([1,2,3,4,5]))
>>> True
print(test_duplicate([1,2,3,4, 4]))
>>> False
2. Given a list in Python and provided the positions of the elements, write a program to swap the two
elements in the list
Answer Code:-
return list
# Running function
pos1, pos2 = 1, 3
3. Write a Python program to sort a tuple by its float element. Sample data: [('item1', '12.20'), ('item2',
'15.10'), ('item3', '24.5')] Expected Output: [('item3', '24.5'), ('item2', '15.10'), ('item1', '12.20')]
Answer Code:-
def Sort(tup):
print(Sort(tup))
Output:-
4. Create a Python class called BankAccount which represents a bank account, having as attributes:
accountNumber (numeric type), name (name of the account owner as string type), balance.
Create a constructor with parameters: accountNumber, name, balance. Create a Deposit() method which
manages the deposit actions.
Create a Withdrawal() method which manages withdrawals actions.
Create an bankFees() method to apply the bank fees with a percentage of 5% of the balance account.
Create a display() method to display account details. Give the complete code for the BankAccount class
Answer Code:-
class BankAccount:
self.accountNumber = accountNumber
self.name = name
self.balance = balance
def Deposit(self , d ):
self.balance = self.balance + d
else:
self.balance = self.balance - w
def bankFees(self):
self.balance = (95/100)*self.balance
def display(self):