CSCI 102 - Intro to Computer Science LAB

Python Assignment: Week 02

Branching

Suggested Order: 102 Week02 Studio; 102 Week2A; 102 Week2B; 101 Lab3; 101 Lab4

Quick Links: zyBook | AutoGrader | Piazza | Canvas | CS @ Mines


Week 02 Python Assignment
Due by Monday, July 19th, 11:45PM
        Part A: Twitter Decoding
        Part B: Enhanced Calculator


Welcome to your assignment for Week 02 of CSCI 102! Each week, after Studio, you should work on that week's homework assignment (lab). This lab is to be done on your own (not pair programming), and needs to be completed and submitted to Canvas no later than the due date. Unlike CSCI 101, we will place all assignments for a given week on one HTML page. This is your Week 2 CSCI 102 Assignment page.

You have TWO problems to do this week, both of which you will SUBMIT to Canvas. Details on Part A and Part B are below.

Part A: Twitter Decoding (4 points)

Introduction

To get started, open IDLE and then create a New File via the File menu. We suggest you immediately save this file in the directory you created to manage all 102 Python Labs this semester. Save this file as
Week2A-twitter.py.

Section 17.10 in your zyBook (an optional Section that we encourage you to do, though not required) provides a program that decodes a few common abbreviations in online communication. For example, in Twitter or Messages, one might use LOL instead of typing "laughing out loud". Your goal in this assignment is to augment the code provided in our zyBook in order to expand the number of abbreviations that can be decoded. Specifically, add these popular abbreviations: BTW, DM, AFAIK, and IDK.

Lab I/O Format

Throughout this semester we will use a specific Lab Input/Output Format. This format is described below:
  • When prompting for input, use the prompt string WORD>, where WORD is a single, uppercase word which describes the input. For example, this lab might choose: TWEET>.
  • When providing output that will be graded, start the line with OUTPUT. Think of this as "boxing your answer" on a math worksheet; it lets us quickly find your answer. Our grading script will skip any output lines that do not start with OUTPUT.
  • You are welcome (and should!) have other output lines that do not begin with OUTPUT; while our grading script will ignore these, good programmers include print statements that are informational to the user of the program.
  • As mentioned, you are expanding Section 17.10 section of zyBooks, which shows all output in lowercase. Thus, use lower case for the new abbreviations as well, including "i don't know".

Example Execution

Enter the Tweet or Message abbreviation to decode.
TWEET> IDK
The decoded abbreviation is:
OUTPUT IDK = i don't know

Comments

All Python files should include a header with your name, section, assignment info, references (i.e., who did you collaborate with on this assignment?; what resource did you use?), and approximate time taken to do the assignment. Be sure to cite any allowed external references used to complete the assignment. Any code without this header will lose 1 point. Here's an example:
        #  Tracy Camp
        #  CSCI 102 – Section A
        #  Week 2A - Twitter Decoding
        #  References: TA Abi for if syntax
        #  Time: 20 minutes

Part B: Enhanced Calculator (4 points)

To get started, open IDLE and then create a New File via the File menu. We suggest you immediately save this file in the directory managing all your 102 Python Labs this semester. Please save this file with the following name: Week2B-enhanced_calculator.py.

Consider our Simple Calculator from Week 1B, which asks the user for two real numbers, calculates four operations, and outputs the result. In this lab, your program should only complete a single operation (i.e., an operation chosen by the user).
  1. Declare operand_one and operand_two variables, initializing each to 0.0.
  2. Declare the variables sum, difference, product, quotient and remainder, and initialize each to 0.0.
  3. Prompt the user to input a real number as the first operand, assigning it to your operand_one variable.
  4. Prompt the user to input a real number as the second operand, assigning it to your operand_two variable.
  5. Ask the user which operation they would like to have performed.
  6. Calculate the result of the operation.
  7. Output the result based on the user's choice. Include TWO decimal places for addition, subtraction, and multiplication and ZERO decimal places for division.
Hint: As before, for division, use operand_one as the dividend and operand_two as the divisor.

Lab I/O Format

Thoughout this semester we will often use a specific Lab Input/Output Format. This format is described below:
  • When prompting for input, use the prompt string WORD>, where WORD is a single, uppercase word which describes the input. For example, this lab might choose: FIRST>, SECOND> and OPERATION>.
  • When providing output that will be graded, start the line with OUTPUT. Think of this as "boxing your answer" on a math worksheet; it lets us quickly find your answer. Our grading script will skip any output lines that do not start with OUTPUT.
  • You are welcome (and should!) have other output lines that do not begin with OUTPUT; while our grading script will ignore these, good programmers include print statements that are informational to the user of the program.

Example Execution #1

Welcome to our Enhanced Calculator!
Input the first operand.
FIRST> 3.14
Input the second operand.
SECOND> 2.72

Choose one of the following operations:
  1 - addition
  2 - subtraction
  3 - multiplication
  4 - division
OPERATION> 2

The result of the subtraction is: 0.42
OUTPUT 0.42
Thank you for using our calculator.


Example Execution #2

Welcome to our Enhanced Calculator!
Input the first operand.
FIRST> 12
Input the second operand.
SECOND> 7

Choose one of the following operations:
  1 - addition
  2 - subtraction
  3 - multiplication
  4 - division
OPERATION> 4

The result of the division is: 1 (quotient) and 5 (remainder)
OUTPUT 1
OUTPUT 5
Thank you for using our calculator.


Comments

All Python files should include a header with your name, section, assignment info, references (i.e., who did you collaborate with on this assignment?; what resource did you use?), and approximate time taken to do the assignment. . Be sure to cite any allowed external references used to complete the assignment. Any code without this header will lose 1 point. Here's an example:
        #  Tracy Camp
        #  CSCI 102 – Section A
        #  Week 2B - Enhanced Calcuator
        #  References: Instructor Megan helped me get started
        #  Time: 25 minutes

Submit Solutions

Follow these steps to submit your files to Canvas.
  1. In Canvas, go to Assignments > Week2A and upload Week2A-twitter.py.
  2. In Canvas, go to Assignments > Week2B and upload Week2B-enhanced_calculator.py.
To receive full credit, your code must execute in Python 3, and you must submit a single file for each portion of the assignment (your Python code file). In addition, your code must follow the Lab I/O Format.

Whenever you submit something to Canvas, we strongly recommend you always double check what you submitted actually got submitted correctly (e.g., did the file upload correctly? did you submit the correct file? etc.) If your submission is incorrect, it's on you.