Demo entry 6046116

Joss TestCode

   

Submitted by Joss Test on Sep 21, 2016 at 18:06
Language: Python 3. Code size: 2.2 kB.

#This allows the use of sys.exit to quit the program
import sys
#This allows us to use pi
import math

#the use of \n in a printed string escapes to a new line
def menu():
    print ("Welcome to the Area of a Shape Calculator")
    print ("*****************************************\n")
    option = input("Calculate the area of a (R)ectangle, (C)ircle ot (T)riangle? Type (E)xit to exit. >> ")
    option = option.upper()

    if option == "R":
        rectangle()
        
    elif option == "C":
        circle()

    elif option == "T":
        triangle()
        
    elif option == "E":
        exit()

    else:
        print ("Hmm not quite sure about that entry - I will return you to the menu\n")
        menu()
        
def rectangle():
    height = float(input("Please enter the height of the rectangle? "))
    width = float(input("Please enter the width of the rectangle? "))
    area_rect = height * width
    print (area_rect,"\n")
    menu()

def circle():
    radius = float(input("Please enter the radius of the circle? "))
    area_circle = math.pi * radius ** 2
    print (round(area_circle,2),"\n")
    menu()

def triangle():
    print ("Dummy function - where area of a triangle would appear\n\n")
    menu()

def exit():
    print ("Many thanks for using the area calculator - Goodbye")
    sys.exit

    
#Non of the above functions will run until they are called
#The program will start by calling the menu function  

#menu1 is a demonstartion only of how """three quotes""" lays text out on the screen
def menu1():
    print ("Welcome to the Area of a Shape Calculator")
    print ("*****************************************\n\n")
    option = input(("""Please choose a shape:\n
    Rectangle - Press 1
    Circle    - Press 2
    Triangle  - Press 3
    >>  """))
                   
    if option == "1":
        rectangle()
        
    elif option == "2":
        circle()

    elif option == "3":
        triangle()
        
    elif option == "4":
        exit()

    else:
        print ("Hmm not quite sure about that entry - I will return you to the menu\n")
        menu()

                
menu1()               

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).