Homework: Simplifying with Functions
The homework is to recreate the Guessing game but adding functions. It’s harder then it sounds. Basically, you want to pull functionality/code out from the main part of the program and create functions. Add in error checking for user responses Make a copy of guess2.py from the Modules homework and call it guess3.py. Modify the…
Read MoreCurrent Guessing Game
Not enough permissions to view this content.
Read MoreHomework: More Function Practice
Not enough permissions to view this content.
Read MoreIntro to Functions
Quick Review: Functions work by allowing us to call a bit of code to run from our main program. Types of Functions There are two types of functions in Python – built-in and user defined. We have already learned how to use a number of the built-in functions including: print() input() int() range() slice() len()…
Read MorePart 3: Create a Bank Class
Now let’s revisit our Account Class and create a class called Bank. This class should have three attributes: name checking – which is of the type Account savings – which is of the type Account Because we are doing it this way – you no longer need your separate classes of checking and savings from…
Read MoreFlowcharts
Flowcharts Uses these elements to help you layout how a program works: squares (actions) diamonds (decision) arrows (flow) Here’s a flowchart depiction of the adventure.py program which you just made for homework.
Read MoreHomework: Design a Program
Create a file called guess.py to make the game below. But first – create a flowchart or pseudocode version of this program. First – assign a number of your choosing to a variable. Get the guess from input from the user. Compare the guess to the real number. If right – give a correct message…
Read MoreSlicing Strings
The basic syntax for using slice with strings is: string[startposition:endposition] Here are some examples: myString = “EvaMargotMLHadleyMaxwellKaramLuke” #returns first three characters mystring[0:3] ‘Eva’ #You can also do it like this mystring[:3] ‘Eva’ mystring[9:11] ‘ML’ #returns last four characters mystring[-4:] ‘Luke’ Reverse Strings This is even cooler – you can reverse a list by using this:…
Read MoreHomework: While Loops
Today, we will create some loops to get comfortable with using them before we start into our Capstone project for the next lesson. Boring but Useful Create a file called while.py in PythonAnywhere. In that file create the following four loops. Create a while loop that sets the initial weather to sunny. While it is…
Read MoreHomework using Modules
Copy guess.py to a new file called guess2.py to include the following features. Have the program generate a random number between two numbers like 1 and 100 for the user to figure out. Set a timer when the user begins guessing and stop it when they finish. Let them know at the end how long…
Read More