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
55 changes: 55 additions & 0 deletions Demos/Module3/simple_calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import math

print("Simple Calculator")
print('------------------------')
print('Enter "quit" to leave the program')

while(1) :
op = input('Provide operation (add,sub,mul,div,circ): ')

if(op.lower() == 'quit'):
break
elif(op in ('add','sub','mul','div','circ')):
data1 = input('Provide first value: ')
if(data1.isnumeric() != True):
print("Please provide a numeric value")
continue
data2 = input('Provide second value: ')
if(data1.isnumeric() != True):
print("Please provide a numeric value")
continue

try:
d1 = float(data1)
except:
d1 = 0.0
print("Data1 did not convert well")
try:
d2 = float(data2)
except:
d2 = 0.0
print("Data2 did not convert well")

if(op == 'add'):
result = d1 + d2
elif(op == 'sub'):
result = d1 - d2
elif(op == 'mul'):
result = d1 * d2
elif(op == 'div'):
try:
result = d1/d2
except ZeroDivisionError:
result = 0
print("Error: Can not divide by 0!")
except ZeroDivisionError:
result = 0
print("Something worse happened with division")
elif(op == 'circ'):
result = math.pi * 2 * d1
else:
print ('Please provide valid operation')
print(f'The result of {data1} {op} {data2} is {round(result,2)}')

else :
print ('Please provide valid operation')
34 changes: 17 additions & 17 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
Comment thread
danbruno101 marked this conversation as resolved.
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 @@ -79,20 +79,20 @@ x = -100
from math import sqrt
x > 0 and sqrt(x)
```
1. [ ] Yes
1. [x] Yes
1. [ ] 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
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 @@ -146,11 +146,11 @@ y = x
1. [ ] One object, one reference
1. [ ] Two objects, one reference
1. [ ] Two objects, two references
1. [ ] One object, two references
1. [x] 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)