In addition to the concepts below, you should know the concepts that were tested on all the quizzes in the course:
Historically, the final exam includes questions about each of the big ideas and skills in the course, such as:
Below are some of the new topics covered since the last quiz, as well as some additional practice problems.
__init__
methodtoString()
methodself
variableWhile you will need to understand how objects work, you do not need to memorize the methods and objects for the Zelle graphics library
main()
function and at least one additional function.The following is a sample run of the program:
I'm thinking of a number between 1 and 100.
Enter guess: 50
Number is higher than 50
Enter guess: pony
Invalid, try again: 588
Invalid, try again: 75
Number is lower than 75
Enter guess: 62
Number is lower than 62
Enter guess: 56
Correct!
You guessed it in 4 tries!
Student
class that stores information for a Swarthmore student. The class should include the following instance variables:id
, an integer identifier for the studentlastName
, a string for the student’s last namecredits
, an integer representing the number of course-credits the student has earnedcourseLoad
, an integer representing the current number of credits in progressWrite the following methods for your Student
class:
Student
object with those values, as well as 0 course-credits and 0 course load.stu1 = Student(25,"Knerr")
registerCurrent()
method that sets the current course load. The course load must be positive and not greater than 4 credits, otherwise no change happensstu1.registerCurrent(3)
withdraw()
method, which decreases the course load by one credit (but courseLoad
should never go below 0).stu1.withdraw()
passedCourse()
method, which removes one course from the current course load and adds to the student’s overall course-credits.stu1.passedCourse()
createEmail()
method, which returns a string. The string should be an email address of the student’s name combined with their ID and the post-fix @swarthmore.edu
. For example, a student with last name "Knerr"
, and ID 25
should return "knerr25@swarthmore.edu"
email = stu1.createEmail()
print(email)
toString()
method that returns a string representation of the object. E.g., "ID: 25\nName: Knerr\nEarned credits: 17\nCourse load: 2"
print(stu1.toString())
Finally, write a main()
method that tests the class. Each method should be tested at least once.
"hello"
and "*"
would return "*h*e*l*l*o*"
:>>> insertChar("hello","*")
'*h*e*l*l*o*'
>>> insertChar("a",'+')
'+a+'
>>> insertChar("","-")
''
wc = [['around', 99], ['beer', 300], ['bottle', 3], ['bottles', 297], ['buy', 1], ['down', 99]]
Write a function to take a word-count list and return the word that has the highest count. For example, if called on the list above, the function should return "beer"
.