Skip to content

Instantly share code, notes, and snippets.

@Mr-Coxall
Last active July 1, 2018 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mr-Coxall/068535e13402688f9897263f40eaa08e to your computer and use it in GitHub Desktop.
Save Mr-Coxall/068535e13402688f9897263f40eaa08e to your computer and use it in GitHub Desktop.
circumference.py
# Created by: Mr. Coxall
# Created on: Sep 2018
# Created for: ICS3U
# This program calculates the circumference of a circle,
# when you give it the radius
import ui
def calculate_touch_up_inside(sender):
# calculate circumference
# constants
PI = 3.14
# input
radius = int(view['radius_textbox'].text)
# process
circumference = 2 * PI * radius
# output
view['answer_label'].text = 'The circumference is: ' + str(circumference) + ' cm'
view = ui.load_view()
view.present('full_screen')
[
{
"selected" : false,
"frame" : "{{0, 0}, {1024, 768}}",
"class" : "View",
"nodes" : [
{
"selected" : false,
"frame" : "{{48, 51}, {350, 32}}",
"class" : "Label",
"nodes" : [
],
"attributes" : {
"font_name" : "<System>",
"frame" : "{{437, 368}, {150, 32}}",
"uuid" : "F703535A-A8E3-4DAE-AAB6-CA05FA9DD140",
"class" : "Label",
"alignment" : "left",
"text" : "Enter the radius of the circle.",
"name" : "instruction_label",
"font_size" : 18
}
},
{
"selected" : true,
"frame" : "{{198, 115}, {200, 32}}",
"class" : "TextField",
"nodes" : [
],
"attributes" : {
"placeholder" : "Place radius here.",
"font_name" : "<System>",
"frame" : "{{412, 368}, {200, 32}}",
"spellchecking_type" : "default",
"class" : "TextField",
"uuid" : "CAC02D03-6C20-4BFC-B666-949D915726A0",
"alignment" : "left",
"autocorrection_type" : "default",
"name" : "radius_textbox",
"font_size" : 17
}
},
{
"selected" : false,
"frame" : "{{48, 115}, {133, 32}}",
"class" : "Label",
"nodes" : [
],
"attributes" : {
"font_name" : "<System>",
"frame" : "{{437, 368}, {150, 32}}",
"uuid" : "591FAAEA-97F4-452E-9448-AE039A8A87C5",
"class" : "Label",
"alignment" : "left",
"text" : "Radius:",
"name" : "radius_label",
"font_size" : 18
}
},
{
"selected" : false,
"frame" : "{{48, 176}, {80, 32}}",
"class" : "Button",
"nodes" : [
],
"attributes" : {
"action" : "calculate_touch_up_inside",
"frame" : "{{472, 368}, {80, 32}}",
"title" : "Calculate",
"uuid" : "4BC43793-D0CC-444F-9A00-D25A592DECD9",
"class" : "Button",
"name" : "calculate_button",
"font_size" : 15
}
},
{
"selected" : false,
"frame" : "{{48, 241}, {350, 32}}",
"class" : "Label",
"nodes" : [
],
"attributes" : {
"font_name" : "<System>",
"frame" : "{{437, 368}, {150, 32}}",
"uuid" : "FA68DC6F-753A-41C8-BA16-FD3D7DC537E4",
"class" : "Label",
"alignment" : "left",
"text" : "The circumference 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