Introduction
These are some practice exercises for you to prepare for Tuesday’s quiz! As mentioned in the FAQ, the quiz will essentially make you write programs to test your understanding of the content so far, similar to the exercises! We won’t be as decriptive with these in this practice because we want you to be able to recognize when to use certain concepts based off what we are asking you to do - that’s the main challenge! Also solutions along with videos explainations will be released at some point, so we want you to do as much as you can on your own :)
Setup Practice Directory
Open the course workspace in VS Code (File > Open Recent > comp110-workspace-…) and open the File Explorer pane. Expand exercises
.
Right click on the word exercises
and select “New Folder”.
Name the folder exactly: practice
and create a new file called quiz00.py
.
Part 1 - Practice with Strings and Characters!
Write a function called ayeee that takes in a string, and returns the count of how many ‘a’s’ are in that string
Functional Requirements – ayeee
- Have a function with the following signature:
- Name:
ayeee
- Arguments: a
str
- Returns: an
int
- Name:
- Keep in mind the
str
will be of variable length meaning your function should be able to handlestr
s of any length.
Part 2 - Practice with Comparisons!
Write a function called ayooo that takes three strings, returns whether or not any of the strings has greater than 10 a’s.
Functional Requirements – ayooo
- Have a function with the following signature:
- Name:
ayooo
- Arguments: three
str
s - Returns: a
bool
- Name:
- Must use the
ayeee
function that you previously! - There are multiple routes you can take with this, but we challenge you to try two ways (sorry if this is extra, but finding multiple ways to solve a problem is great practice)!
- One way is where you can check each one to see if you can find a
str
that’s greater than 10. - Another way is where you use logical operators like
or
,and
. This can be done with one line of code! Do not stress if you cannot get it to be one line, it is just something interesting and challenging to think about!
- One way is where you can check each one to see if you can find a
Part 3 - Practice with Expressions!
Write a function called yay_pass_fail takes in a course grade (before the exam) and a major, and returns the final exam grade needed in order to pass the class (at least a 60).
Functional Requirements – yay_pass_fail
- Have a function with the following signature:
- Name:
yay_pass_fail
- Arguments: a
float
, astr
- Returns: a
float
- Name:
- The weight of the final exam will be dependent on the major:
- If the major is computer science, the final exam grade is worth 20% of your course grade
- If the major is chemistry or if the major is biology, the final exam grade is worth 40% of your course grade
- Otherwise, your exam grade is worth 30% of your course grade
- Really think about how a course grade is calculated. We essentially have two ‘categories’ here, the course grade before the exam, and the final exam, each with a particular weight depending on the class. Keep in mind you need a 60 to pass the class.
- Negatives and zero return values are okay for this! Just means you killed the course and don’t need the final :)
Part 4 - Practice with Loops!
Write a function called time_loop that takes in a string that will ask the user repeatedly “You are in a time loop, enter the password to get out!” until the user will type in that string as the password, to which the time loop will end, and the number of tries it took gets returned.
Functional Requirements – time_loop
- Have a function with the following signature:
- Name:
time_loop
- Arguments: a
str
- Returns: an
int
- Name:
- The same prompt should be repeated until the user gets the password correct.
Testing your program
Use the print feature outside of your declared functions to test each one of your functions out! Best way to do this is think of some arguments that you can pass in (that matches the types declared for the function parameters) and have an expected return value in mind. The actual return value should be printed and then compare it with what you expected it to be, and try this for different combinations of them for each function!
Style and Documentation Requirements
While you are not submitting anything for this, it is always good practice to write your meaningful doc strings and have proper style in all your variable names, keeping in mind things such as types, magic numbers, etc.