Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Quizzes/quiz01.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

**In Python 3, the maximum value for an integer is 263 - 1:**

1. [ ] False
1. [ X ] False
1. [ ] True

**How would you express the hexadecimal value a5 as a base-16 integer constant in Python?**

1. [ ] 0xa5
1. [X ] 0xa5
1. [ ] a5x0
1. [ ] 00xa5
1. [ ] 0xaa


**Which of the following are valid ways to specify the string literal blue'car in Python:**

1. [ ] """blue'car"""
1. [X ] """blue'car"""
1. [ ] 'blue''car'
1. [ ] 'blue\'car'
1. [ ] "blue'car"
1. [ X] 'blue\'car'
1. [ X] "blue'car"
1. [ ] 'blue'car'

**Which of the following is the correct output?**
Expand All @@ -30,12 +30,12 @@ print(r'blue\\car\nwindow')
1. [ ] blue\car\nwindow
1. [ ] blue\\carwindow
1. [ ] blue\car window
1. [ ] blue\\car\nwindow
1. [X ] blue\\car\nwindow

**Which of the following is not a Python built-in function:**

1. [ ] round()
1. [ ] repr()
1. [ ] diff()
1. [X ] diff()
1. [ ] map()
1. [ ] isinstance()
36 changes: 18 additions & 18 deletions Quizzes/quiz02.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ print(sum(xs))
```

1. [ ] It's impossible to know.
1. [ ] 13
1. [ X ] 13
1. [ ] Something else.

**In the Python statement x = a + 5 - b:**

- a and b are ________
- a + 5 - b is ________

1. [ ] operands, an expression
1. [ X ] operands, an expression
1. [ ] terms, a group
1. [ ] operands, an equation
1. [ ] operators, a statement

**What is the value of the expression 100 / 25?

1. [ ] 4
1. [ ] 4.0
1. [ X ] 4.0

**You should use the == operator to determine whether objects of type float are equal.**

1. [ ] True
1. [ ] False
1. [ X ] False

```python
1.1 + 2.2 == 3.3
Expand All @@ -44,15 +44,15 @@ y = (x < 100.0) and isinstance(x, float)
```

1. [ ] None
1. [ ] True
1. [ X ] True
1. [ ] Correct
1. [ ] 1
1. [ ] 0
1. [ ] False

**Which of the following are truthy:**

1. [ ] 0.000001
1. [X ] 0.000001
1. [ ] 0
1. [ ] []
1. [ ] True
Expand All @@ -67,7 +67,7 @@ b = 200
```

1. [ ] 0
1. [ ] 200
1. [ X ] 200
1. [ ] 100
1. [ ] False
1. [ ] True
Expand All @@ -80,19 +80,19 @@ from math import sqrt
x > 0 and sqrt(x)
```
1. [ ] Yes
1. [ ] No
1. [ X ] No

**Which of the following operators has the lowest precedence?**

1. [ ] and
1. [ X ] and
1. [ ] not
1. [ ] %
1. [ ] +
1. [ ] **

**What is the value of the expression 1 + 2 ** 3 * 4?**

1. [ ] 33
1. [ X ] 33
1. [ ] 36
1. [ ] 108
1. [ ] 4097
Expand All @@ -106,13 +106,13 @@ x *= 5
x = x * 5
```

1. [ ] True
1. [ X ] True ** considering that both statements are not used in the same program one after the other else the first x returns 500, the second one returns 2500. The statements are equivalent one or the other can be used
1. [ ] False

**The Python Enhancement Proposal (PEP) that enumerates stylistic guidelines for Python code is:**

1. [ ] PEP 8000
1. [ ] PEP 8
1. [ X ] PEP 8
1. [ ] PEP 257
1. [ ] PEP 20

Expand All @@ -126,16 +126,16 @@ x, y = 1, 2
print(x, y, z)
```
1. [ ] True
1. [ ] False
1. [ X ] False

**Variables must be declared before they are assigned a value.**

1. [ ] True
1. [ ] False
1. [ X ] False

**Variables may be assigned a value of one type, and after be assigned a value of a different type.**

1. [ ] True
1. [ X ] True
1. [ ] False

**How many objects and how many references are created by this program?**
Expand All @@ -145,12 +145,12 @@ y = x

1. [ ] One object, one reference
1. [ ] Two objects, one reference
1. [ ] Two objects, two references
1. [ ] One object, two references
1. [ X ] Two objects, two references
1. [ ] One object, two references

**PEP8 recommend which of the following styles for multi-word variable names:**

1. [ ] customerFirstName (Camel Case)
1. [ ] CustomerFirstName (Pascal Case)
1. [ ] customer_first_name (Snake Case)
1. [ X ] customer_first_name (Snake Case)
1. [ ] customer-first-name (Kebab Case)
71 changes: 71 additions & 0 deletions my_labs_solution/lab3_sol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

def add(fnum, snum):
try:
result = float(fnum) + float(snum)
except Exception as e:
result = 'N/A'
print(e)
print('something went wrong')
finally:
return result

def sub(fnum, snum):
try:
result = float(fnum) - float(snum)
except Exception as e:
result = 'N/A'
print(e)
print('something went wrong')
finally:
return result

def mul(fnum, snum):
try:
result = float(fnum) * float(snum)
except Exception as e:
result = 'N/A'
print(e)
print('something went wrong')
finally:
return result

def div(fnum, snum):
try:
result = float(fnum)/float(snum)
except ZeroDivisionError as e:
result = 'N/A'
print(e)
print('snum cannot be zero for operation "/"')
except Exception as ex:
result = 'N/A'
print(ex)
print('something went wrong')
finally:
return result


def calculate(operation, fnum, snum):
if(operation in ('+', '-', '*', '/')):
if(operation == '+'):
return add(fnum, snum)
elif (operation == '-'):
return sub(fnum, snum)
elif (operation == '*'):
return mul(fnum, snum)
else:
return div(fnum, snum)
else:
print(f'Operation not supported, {operation}\nOperations supported are : +, -, *, /')

def main():
#get the operation
operation = input("Please enter Operation: ")
#get the input params
fnum = input("Please enter First Num: ")
snum = input("Please enter the Second Num: ")
#calculate
result = calculate(operation, fnum, snum)
print(f'Result: {result}')

if __name__ == "__main__":
main()
142 changes: 142 additions & 0 deletions my_labs_solution/lab_4_calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@


def add(fnum, snum):
return fnum + snum

def sub(fnum, snum):
return fnum - snum

def mul(fnum, snum):
return fnum * snum

def div(fnum, snum):
try:
result = fnum/snum
except ZeroDivisionError as e:
result = 'N/A'
print(e)
print('snum cannot be zero for operation "/"')
finally:
return result


def arithm_calc(operation, fnum, snum):
if(operation in ('+', '-', '*', '/')):
if(operation == '+'):
return add(fnum, snum)
elif (operation == '-'):
return sub(fnum, snum)
elif (operation == '*'):
return mul(fnum, snum)
else:
return div(fnum, snum)
else:
print(f'Operation not supported, {operation}\nOperations supported are : +, -, *, /')

def list_attr_calc(list_1, list_2):
result = {}
list_1.sort()
list_2.sort()
result['list_1'] = {'min_value' : list_1[0], 'max_value' : list_1[-1], 'len' : len(list_1)}
result['list_2'] = {'min_value' : list_2[0], 'max_value' : list_2[-1], 'len' : len(list_2)}
return result

def list_sort_calc(list_1, list_2):
result = []
result.extend(list_1)
result.extend(list_2)
result.sort()
return result

def set_calc(operation, list_1, list_2):
if operation in ('Union', 'Difference', 'Intersect'):
result = set()
s1 = {*list_1}
s2 = {*list_2}
if(operation == 'Union'):
result = s1.union(s2)
elif(operation == 'Difference'):
result = s1.difference(s2)
else:
result = s1.intersection(s2)
return result
else:
print(f'Operation not supported, {operation}\nOperation supported are : [Union, Difference, Intersect]')

def check_value(num):
try:
val = float(num)
except Exception as e:
print(e)
print("num is not numeric")
finally:
return val

def check_list(l):
for i in range(len(l)):
l[i] = check_value(l[i])
return l

def get_inputs_for_arithm():
operation = input("Please enter Operation: ")
#get the input params
fnum = input("Please enter First Num: ")
fnum = check_value(fnum)
snum = input("Please enter the Second Num: ")
snum = check_value(snum)

input_dict = {}
input_dict['operation'] = operation
input_dict['fnum'] = fnum
input_dict['snum'] = snum
return input_dict

def get_inputs_for_list():
st_list_1 = input("Please enter List1 in following format: 1,2,3,4,5: ")
list_1 = st_list_1.split(',')
list_1 = check_list(list_1)
st_list_2 = input("Please enter List2 in following format: 1,2,3,4,5: ")
list_2 = st_list_2.split(',')
list_2 = check_list(list_2)
input_dict = {}
input_dict['list1'] = list_1
input_dict['list2'] = list_2
return input_dict

def get_inputs_for_set():
operation = input("Please enter operation performed on set -> [Union, Difference, Intersect]: ")
st_list_1 = input("Please enter List1 in following format: 1,2,3,4,5: ")
list_1 = st_list_1.split(',')
list_1 = check_list(list_1)
st_list_2 = input("Please enter List2 in following format: 1,2,3,4,5: ")
list_2 = st_list_2.split(',')
list_2 = check_list(list_2)
input_dict = {}
input_dict['operation'] = operation
input_dict['list1'] = list_1
input_dict['list2'] = list_2
return input_dict


def main():
#get the operation
mode = input("Please enter one of the following Modes[SET, ARITHM, LISTATTR, LISTSORT]: ")
if(mode == 'SET'):
input_dict = get_inputs_for_set()
result = set_calc(input_dict['operation'], input_dict['list1'], input_dict['list2'])
elif(mode == 'ARITHM'):
input_dict = get_inputs_for_arithm()
result = arithm_calc(input_dict['operation'], input_dict['fnum'], input_dict['snum'])
elif(mode == 'LISTATTR'):
input_dict = get_inputs_for_list()
result = list_attr_calc(input_dict['list1'], input_dict['list2'])
elif(mode == 'LISTSORT'):
input_dict = get_inputs_for_list()
result = list_sort_calc(input_dict['list1'], input_dict['list2'])
else:
print(f'Mode not supported, {mode}\nModes supported are : [SET, ARITHM, LISTATTR, LISTSORT]')

print(f'Result: {result}')

if __name__ == "__main__":
main()
Loading