In this video, Annyce provides a walkthrough of her solution to the "Favorite cities" challenge.
(upbeat music) - Welcome back. I hope you had fun thinking of your favorite cities and writing the code for this challenge. Here's the solution I came up with. On line number one, I just have a comment. It prints out the name of a favorite city, because that's what our function does. Then on line number two, we have the function definition. Notice that we're using the def keyword. This is how we let Python know that we are creating a function. It takes in one parameter named Name. Then, inside of our function on line number three, we use the variation of the print method that first displays a string, one of my favorite cities is, and then it prints out the value of the name variable with a space before it. On line number five, I call the favorite city function with one of my favorite cities, Santa Barbara, California. Then on line number six, I call it again with another one of my favorite cities, Asheville, North Carolina. And finally, on line number seven, we call our function using Amsterdam, The Netherlands. Let's run this code and check out the output. Yay, it called the function three different times, with each of my favorite cities. Cool! Were you able to use a function to print out your favorite cities? How'd it go? Did you come up with something similar? I hope so. Breaking up our code into reusable chunks helps us to develop programs that are easier to read, write, and debug. Now you have one more tool in your programmer's belt.
- Writing source code
- Basic statements and expressions
- Working with numbers and strings
- Writing conditional code
- Increasing your efficiency with functions
- Working with comments
- Making decisions in code
- Troubleshooting errors
- Learning about other languages
Skill Level Beginner
Programming Foundations: Fuzzy Logicwith Erin Colvin41m 50s Intermediate
Programming Foundations: Algorithmswith Joe Marini1h 45m Beginner
Programming Foundations: Design Patternswith Elisabeth Robson1h 44m Intermediate
1. Programming Basics
2. Programming Syntax
3. Variables and Data Types
4. Conditional Code
5. Modular Code
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.