From the course: Programming Foundations: Fundamentals

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Solution: Favorite cities

Solution: Favorite cities

(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…

Contents