Last active
July 1, 2018 02:50
-
-
Save Mr-Coxall/1e8a459350dcff3e6dcf6f165a394820 to your computer and use it in GitHub Desktop.
pizza.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Created by: Mr. Coxall | |
# Created on: Sep 2018 | |
# Created for: ICS3U | |
# This program calculates the cost of a pizza, give the diameter | |
import ui | |
def calculate_button_touch_up_inside(sender): | |
# calculate circumference | |
# constants | |
PI = 3.14 | |
LABOUR_COST = 0.75 | |
RENT_COST = 1.00 | |
MATERIAL_COST = 0.50 | |
HST = 0.13 | |
# input | |
diameter = float(view['diameter_textbox'].text) | |
# process | |
sub_total = LABOUR_COST + RENT_COST + (MATERIAL_COST * diameter) | |
cost = sub_total + (sub_total * HST) | |
# output | |
# got currency format from here: | |
# http://stackoverflow.com/questions/21208376/converting-float-to-dollars-and-cents | |
view['answer_label'].text = 'The cost is: ' + '${:,.2f}'.format(cost) | |
view = ui.load_view() | |
view.present('full_screen') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"selected" : false, | |
"frame" : "{{0, 0}, {1024, 768}}", | |
"class" : "View", | |
"nodes" : [ | |
{ | |
"selected" : true, | |
"frame" : "{{47, 47}, {354, 32}}", | |
"class" : "Label", | |
"nodes" : [ | |
], | |
"attributes" : { | |
"font_name" : "<System>", | |
"frame" : "{{437, 368}, {150, 32}}", | |
"uuid" : "DE68642C-9912-4E59-B755-7A5208C521C0", | |
"class" : "Label", | |
"alignment" : "left", | |
"text" : "Enter the diameter of pizza, in inches.", | |
"name" : "instructions_label", | |
"font_size" : 18 | |
} | |
}, | |
{ | |
"selected" : false, | |
"frame" : "{{47, 111}, {200, 32}}", | |
"class" : "TextField", | |
"nodes" : [ | |
], | |
"attributes" : { | |
"placeholder" : "Diameter in inches", | |
"font_name" : "<System>", | |
"frame" : "{{412, 368}, {200, 32}}", | |
"spellchecking_type" : "default", | |
"class" : "TextField", | |
"uuid" : "8F350EFE-0CC4-4D76-B146-938500D9E36B", | |
"alignment" : "left", | |
"autocorrection_type" : "default", | |
"name" : "diameter_textbox", | |
"font_size" : 17 | |
} | |
}, | |
{ | |
"selected" : false, | |
"frame" : "{{321, 111}, {80, 32}}", | |
"class" : "Button", | |
"nodes" : [ | |
], | |
"attributes" : { | |
"action" : "calculate_button_touch_up_inside", | |
"frame" : "{{472, 368}, {80, 32}}", | |
"title" : "Calculate", | |
"uuid" : "31D068E8-13DD-4E7C-AED4-46EBE6AC806D", | |
"class" : "Button", | |
"name" : "calculate_button", | |
"font_size" : 15 | |
} | |
}, | |
{ | |
"selected" : false, | |
"frame" : "{{47, 175}, {354, 32}}", | |
"class" : "Label", | |
"nodes" : [ | |
], | |
"attributes" : { | |
"font_name" : "<System>", | |
"frame" : "{{437, 368}, {150, 32}}", | |
"uuid" : "CDEFDCA8-F3C9-4D5B-8D0D-E5AE96691579", | |
"class" : "Label", | |
"alignment" : "left", | |
"text" : "The cost is: ", | |
"name" : "answer_label", | |
"font_size" : 18 | |
} | |
} | |
], | |
"attributes" : { | |
"enabled" : true, | |
"background_color" : "RGBA(1.000000,1.000000,1.000000,1.000000)", | |
"tint_color" : "RGBA(0.000000,0.478000,1.000000,1.000000)", | |
"border_color" : "RGBA(0.000000,0.000000,0.000000,1.000000)", | |
"flex" : "" | |
} | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment