-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculatorUsingFile.py
More file actions
70 lines (57 loc) · 2.6 KB
/
CalculatorUsingFile.py
File metadata and controls
70 lines (57 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
################################################################
## Simple Calculator App with File Usage (Jython) ##
## Author: Nick Belli ##
## Date: 04/25/2018 ##
## Uncomment popup boxes for testing and training purposes ##
## Docs are delimited with "## ", commented code is "#" ##
################################################################
## Import csv module to be able to open Excel (csv) files ##
import _csv
## Define program functions in small actionable parts ##
def addTwoNumbers(myNum1, myNum2):
return int(myNum1) + int(myNum2)
def subtractTwoNumbers(myNum1, myNum2):
return int(myNum1) - int(myNum2)
def multiplyTwoNumbers(myNum1, myNum2):
return int(myNum1) * int(myNum2)
def divideTwoNumbers(myNum1, myNum2):
return int(myNum1) / int(myNum2)
def returnMessage():
return 'My result is: ' + str(myResult)
def returnMessage2(myResult):
return 'My result is: ' + str(myResult)
## Welcome users to the application ##
popup("Welcome to the Calculator!")
##Read a row of data from the selected csv file into an array, and then pass the array to readable variables ##
with open("C:\Users\BELLN014\Desktop\Sikuli Scripts\CalculatorTest.csv") as csvfile:
getRow = _csv.reader(csvfile)
#getRow.next()
currentRow = []
for row in getRow:
currentRow = row
myNum1 = currentRow[0]
myNum2 = currentRow[1]
userSelection = currentRow[2]
## Popup boxes to unit test each of file inputs ##
popup('My first number is: ' + myNum1)
popup('My second number is: ' + myNum2)
popup('My selection is: ' + userSelection)
if myNum1.isnumeric() and myNum2.isnumeric():
if userSelection == "Add":
myResult = addTwoNumbers(myNum1, myNum2)
popup(returnMessage())
elif userSelection == "Subtract":
myResult = subtractTwoNumbers(myNum1, myNum2)
popup(returnMessage())
elif userSelection == "Multiply":
popup(returnMessage2(multiplyTwoNumbers(myNum1, myNum2)))
elif userSelection == "Divide":
if int(myNum2) == 0:
popup("You can't divide by Zero!")
else:
myResult = divideTwoNumbers(myNum1, myNum2)
popup(returnMessage())
else:
popup("Please check the file")
## Thank the user to signify the end of the application run ##
popup("Thank you for using the simple calculator")