diff --git a/Quizzes/quiz01.md b/Quizzes/quiz01.md index 382bccc..96b0e3f 100644 --- a/Quizzes/quiz01.md +++ b/Quizzes/quiz01.md @@ -2,12 +2,12 @@ **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 @@ -15,10 +15,10 @@ **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?** @@ -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() diff --git a/Quizzes/quiz02.md b/Quizzes/quiz02.md index 3ae7b5e..8fcbfbe 100644 --- a/Quizzes/quiz02.md +++ b/Quizzes/quiz02.md @@ -9,7 +9,7 @@ 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:** @@ -17,7 +17,7 @@ print(sum(xs)) - 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 @@ -25,12 +25,12 @@ print(sum(xs)) **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 @@ -44,7 +44,7 @@ y = (x < 100.0) and isinstance(x, float) ``` 1. [ ] None -1. [ ] True +1. [ X ] True 1. [ ] Correct 1. [ ] 1 1. [ ] 0 @@ -52,7 +52,7 @@ y = (x < 100.0) and isinstance(x, float) **Which of the following are truthy:** -1. [ ] 0.000001 +1. [X ] 0.000001 1. [ ] 0 1. [ ] [] 1. [ ] True @@ -67,7 +67,7 @@ b = 200 ``` 1. [ ] 0 -1. [ ] 200 +1. [ X ] 200 1. [ ] 100 1. [ ] False 1. [ ] True @@ -80,11 +80,11 @@ 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. [ ] + @@ -92,7 +92,7 @@ x > 0 and sqrt(x) **What is the value of the expression 1 + 2 ** 3 * 4?** -1. [ ] 33 +1. [ X ] 33 1. [ ] 36 1. [ ] 108 1. [ ] 4097 @@ -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 @@ -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?** @@ -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) \ No newline at end of file diff --git a/my_labs_solution/lab3_sol.py b/my_labs_solution/lab3_sol.py new file mode 100755 index 0000000..dac6e98 --- /dev/null +++ b/my_labs_solution/lab3_sol.py @@ -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() \ No newline at end of file diff --git a/my_labs_solution/lab_4_calc.py b/my_labs_solution/lab_4_calc.py new file mode 100755 index 0000000..713f859 --- /dev/null +++ b/my_labs_solution/lab_4_calc.py @@ -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() \ No newline at end of file diff --git a/my_labs_solution/simple_calculator.py b/my_labs_solution/simple_calculator.py new file mode 100755 index 0000000..8d5ba03 --- /dev/null +++ b/my_labs_solution/simple_calculator.py @@ -0,0 +1,10 @@ +#importing math lib to get the value of pi +import math + +#get the radius from the user, convert to float as radius can be anything +radius = float(input("Please Provide the Radius of the Circle: ")) + +#calculate the circumference with 2*pi*r +Circumference = 2 * math.pi * radius + +print(Circumference) \ No newline at end of file