Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone help me with the code to produce this output? Welcome to your friend

ID: 645975 • Letter: C

Question

  Can someone help me with the code to produce this output?    Welcome to your friendly Area Calculator program!                              Area Menu                              1. Calculate the area of a rectangle               2. Calculate the area of a circle               3. Calculate the area of a triangle               4. Quit the program                              Enter your choice :  1                               Okay, I will calculate the area of a rectangle for you.               What is the length of the rectangle?  2                What is the width of the rectangle?  3                               The area of a rectangle is 6.                              Area Menu                              1. Calculate the area of a rectangle               2. Calculate the area of a circle               3. Calculate the area of a triangle               4. Quit the program                              Enter your choice :  2                               Okay, I will calculate the area of a circle for you.                              What is the radius of the circle?  4                                             The area of a circle is 50.26548245743669                                 Area Menu                              1. Calculate the area of a rectangle               2. Calculate the area of a circle               3. Calculate the area of a triangle               4. Quit the program                              Enter your choice :  1                               Okay, I will calculate the area of a rectangle for you.               What is the length of the rectangle?  4                What is the width of the rectangle?  8                               The area of a rectangle is 32.                               Area Menu                              1. Calculate the area of a rectangle               2. Calculate the area of a circle               3. Calculate the area of a triangle               4. Quit the program                              Enter your choice :  4                               Good-bye - Have a great day! 

Explanation / Answer

The above commands will install Python 3 to your home directory, which is probably what you want, but if you skip the --prefix, it will install it to /usr/local. If you want to use the IDLE graphical code editor, you need to make sure that the tk and tcl libraries, together with their development files, are installed on the system. You will get a warning during the make phase if these are not available.

Mac users

Starting from Mac OS X (Tiger), Python ships by default with the operating system, but you will need to update to Python 3 until OS X starts including Python 3 (check the version by starting python3 in a command line terminal). Also IDLE (the Python editor) might be missing in the standard installation. If you want to (re-)install Python, get the MacOS installer from the Python download site.

Windows users

Download the appropriate Windows installer (the x86 MSI installer, if you do not have a 64-bit AMD or Intel chip). Start the installer by double-clicking it and follow the prompts.

See https://docs.python.org/3/using/windows.html#installing-python for more information.

Configuring your PATH environment variable

The PATH environment variable is a list of folders, separated by semicolons, in which Windows will look for a program whenever you try to execute one by typing its name at a Command Prompt. You can see the current value of your PATH by typing this command at a Command Prompt:

echo %PATH%

The easiest way to permanently change environment variables is to bring up the built-in environment variable editor in Windows. How you get to this editor is slightly different on different versions of Windows.

On Windows 8: Press the Windows key and type Control Panel to locate the Windows Control Panel. Once you've opened the Control Panel, select View by: Large Icons, then click on System. In the window that pops up, click the Advanced System Settings link, then click the Environment Variables... button.

On Windows 7 or Vista: Click the Start button in the lower-left corner of the screen, move your mouse over Computer, right-click, and select Properties from the pop-up menu. Click the Advanced System Settings link, then click the Environment Variables... button.

On Windows XP: Right-click the My Computer icon on your desktop and select Properties. Select the Advanced tab, then click the Environment Variables... button.

Once you've brought up the environment variable editor, you'll do the same thing regardless of which version of Windows you're running. Under System Variables in the bottom half of the editor, find a variable called PATH. If there is is one, select it and click Edit.... Assuming your Python root is C:Python34, add these two folders to your path (and make sure you get the semicolons right; there should be a semicolon between each folder in the list):

C:Python34 C:Python34Scripts

Note: If you want to double-click and start your Python programs from a Windows folder and not have the console window disappear, you can add the following code to the bottom of each script:

Interactive Mode

Go into IDLE (also called the Python GUI). You should see a window that has some text like this:

The >>> is Python's way of telling you that you are in interactive mode. In interactive mode what you type is immediately run. Try typing 1+1 in. Python will respond with 2. Interactive mode allows you to test out and see what Python will do. If you ever feel you need to play with new Python statements, go into interactive mode and try them out.

Creating and Running Programs

Go into IDLE if you are not already. In the menu at the top, select File then New File. In the new window that appears, type the following:

Now save the program: select File from the menu, then Save. Save it as "hello.py" (you can save it in any folder you want). Now that it is saved it can be run.

Next run the program by going to Run then Run Module (or if you have an older version of IDLE use Edit then Run script). This will output Hello, World! on the*Python Shell* window.