Interview Questions
1) What is set?
Ans- In Python, a set is an unordered collection of unique elements. It is defined
by enclosing the elements within curly braces `{}`. Sets are mutable, meaning you
can add or remove elements from them.
Here's a basic example of creating a set in Python:
```python
my_set = {1, 2, 3, 4, 5}
2) How to create empty set?
Ans- In Python, you can create an empty set using either the `set()` function or
using a pair of curly braces `{}`.
Here's how you can create an empty set using both methods:
```python
# Using set() function
empty_set1 = set()
# Using curly braces
empty_set2 = {}
# Note: Using curly braces to create an empty set will create an empty dictionary
instead in Python.
```
It's important to note the distinction between using curly braces to create an
empty set versus an empty dictionary. To explicitly create an empty set, it's safer
to use the `set()` function.
3) Write a python program to calculate and print the total price of an item
including tax .prompt the user to enter the price of the item and tax rate.
calculate and display total price
Ans-
price=eval(input('enter price:'))
tax=eval(input('enter tax rate:'))
total_price=price+tax
print(total_price)
#output-
enter price:1000
enter tax rate:18
1018