Description
1. GOALS/OUTCOMES FOR LAB
– To use continue practice with variables and input
– To practice string processing
– To practice formatted output
– To get you more familiar with your PyCharm IDE
– To write your own Python code
2. LAB 2 – TASK/INSTRUCTIONS
Task 0: [This will be the same for all labs]: Start you code with comments that include this lab ID, your full
name, email address, and student id as follows:
# Lab 2
# Author: Michael S. Brown
# Email: msb99898@aol.com
# Student ID: 10233030
This lab has four tasks. Please read each carefully. You can also watch the accompanying video linked here:
Task 1 [Simple exponent]:
– Prompt the user for input in the following form: “x^y”, where x and y are a single digit number, for example
2^8 or 4^2 would be valid inputs.
– Next, output the string “x^y is XXX”, where x and y are replaced with the input values and XXX is the result of
raising x to the y power, e.g., xy
.
Note that this syntax “x^y” is how some other programming languages perform exponent. Recall, Python
uses the ** operator for exponent. Your prompt and output should look like that shown on page 3 of this
document. You may assume that the input is correct. That is, you do not need to include any code to check to
see if the second character is a “^”. We haven’t learned how to do that yet.
Also, see accompanying video linked above.
See next page for Tasks 2-4
Page 2/7
Task 2 [Converting a sentence first half to uppercase and second have to lowercase]
– Prompt the user to input a long sentence (you may assume the user types at least 3 or more characters).
– Remove any spaces that appear before or after the string.
– Print out the length of the string and the middle character as shown on page 3. Note: you should use integer
divide to compute the middle character index.
– Finally, print out the string with the first half (up to, but not including the middle character) are all uppercase
m, followed by a vertical bar symbol “|”, followed by second half of the sentence (from the middle character
to the last character) all in lowercase.
Your output should look like those shown on page 3 of the lab document. Also see accompanying video.
Task 3 [Remove commas, periods, and convert all spaces to * and all letters to lowercase]
– Prompt the user to input a long sentence.
– You should remove any spaces that appear before or after the string.
– Remove all commas and periods from the input.
– Replace all the spaces (” “) in the string with an asterisks *.
– All letters should also be converted to lowercase.
– Printout this processed string.
Your output should look like that shown on page 3 of the lab document. Also see accompanying video.
Note you do not have to perform the operations in the order specified above. Just as long as your output is
the same as the required output.
Task 4 [Highlighting a substring]
– Prompt the user to input a sentence.
– Prompt the user to input a substring (i.e., a smaller sequence of characters that is part of the first sentence).
You may assume this is a valid substring.
– Output the original string, but where the substring first occurs should be modified to be in all uppercase and
be surrounded by asterisks *. See page 3 for an example.
Hint: The .replace() methods will note help for this task. In my opinion, this is the most challenging of the 4
tasks.
Your output should look like that shown on page 3 of the lab document. Also see accompanying video.
Example video for the lab: https://www.eecs.yorku.ca/~mbrown/EECS1015_Lab2.mp4
Page 3/7
Lab 2 – Example output #1 (Key: green are prompts, red is user input, blue is output you generate)
——
Task 1: Type in an exponential in the following form x^y, where x and y are single digits from 0-9
Type exponent here: 2^4
2^4 is 16
——
Task 2: First half upper, second half lower
Type a sentence: This is a long SENTENCE.
The string is 24 chars long. ‘n’ is the middle character.
Modified sentence: THIS IS A LO|ng sentence.
——
Task 3: Remove commas and periods. Convert spaces to * and characters to lowercase.
Type a sentence: Hello, this is another long sentence.
Modified sentence: hello*this*is*another*long*sentence
——
Task 4: Substring highlight
Type a sentence: York University is in Toronto.
Type substring : Toronto
Modified sentence: York University is in *TORONTO*.
Lab 2 – Example output #2
——
Task 1: Type in an exponential in the following form x^y, where x and y are single digits from 0-9
Type exponent here: 8^3
8^3 is 512
——
Task 2: First half upper, second half lower
Type a sentence: Yet another long SENTENCE with mixed CASES.
The string is 43 chars long. ‘E’ is the middle character.
Modified sentence: YET ANOTHER LONG SENT|ence with mixed cases.
——
Task 3: Remove commas and periods. Convert spaces to * and characters to lowercase.
Type a sentence: Strings, integers, and floats are basic DATA TYPES in Python.
Modified sentence: strings*integers*and*floats*are*basic*data*types*in*python
——
Task 4: Substring highlight
Type a sentence: The quick brown fox jumps over the lazy dog.
Type substring : brown
Modified sentence: The quick *BROWN* fox jumps over the lazy dog.
Page 4/7
3. GRADING SCHEME (Maximum number of points possible 10)
This lab is more challenging than lab 1, especially if you are new to programming. However, the notes and
trinkets examples are all sufficient to help you do this lab. The only task that requires some additional thought
is task 4. To get full marks you need to make sure you follow the instructions correctly. The following will be
our grading scheme for the Lab components specified in Section 2 of this document.
Task 0: (0 points, but deduction if you skip this part)
File name must be “lab2.py” (all lowercase, no spaces)
The Python comments at the beginning of your program must include your name, email, and York
student id (this is important for grading)
If your file name is incorrect, your or do not put in the required information we will deduct -5 points
(Why are we so harsh? Because if you don’t put in your name and student id it can be very difficult for
the TAs to determine whose submission this is.)
Task 1-4: (2.5 points each)
Each task should prompt the user correctly and compute the required output correctly.
Please watch the accompanying video.
-No submission – 0 points
-Any submission 1 week after the due date 50% off the total marks
-Any submission 2 weeks after the due date will not be marked and treated as no submission.
See pages below on how to submit your lab code.
MAKE SURE TO SELECT Lab2 with websubmit
Page 5/7
4. SUBMISSIONS (EECS web-submit)
You will submit your lab using the EECS web submit.
Click on the follow URL: https://webapp.eecs.yorku.ca/submit
STEP 1 — If you don’t have an EECS account,
click here to use Passport York (everyone
has a passport York account).
If you do have an EECS account, enter here
and go to STEP 3.
STEP 1 — If you don’t have an EECS account,
click here to use Passport York (everyone
has a passport York account).
If you do have an EECS account, enter here
and go to STEP 3.
STEP 1 — If you don’t have an EECS account,
click here to use Passport York (everyone
has a passport York account).
If you do have an EECS account, enter here
and go to STEP 3.
STEP 2 – Enter your passport York
username/password.
Page 6/7
STEP 3 – Select the correct menu option
as follows. Term “F”, Course “1015”,
Assignment “Lab2”.
STEP 3 cont’ – Select your file. The location
in PyCharm may be complicated. I
recommend you save your PyCharm Python
file to your desktop and select from there.
Remember, name your file lab2.py.
STEP 3 cont’ – once you have entered
everything above, click “Submit Files”.
STEP 4 – Confirm that you have entered
everything in correctly. If you make a
mistake here and submit to the wrong
course, or wrong lab, we won’t be able to
tell and will mark your lab as not submitted.
Please double check before clicking OK.
Lab 2
lab2.py
Page 7/7
For more details on websubmit, see EECS department instructions:
https://wiki.eecs.yorku.ca/dept/tdb/services:submit:websubmit
STEP 5 – After you submit, your webpage
will refresh and show that you have
submitted the files and the time.
I recommend you logout.
You can resubmit the file if you make
changes. However, if the TA has already
graded your lab, they will not grade it again,
so I recommend you only upload once you
have it work.
lab2.py
lab2.py