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 - Python Tutorial
From the course: Programming Foundations: Fundamentals
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
Introduction to functions3m 45s
-
(Locked)
Creating and calling functions3m 47s
-
(Locked)
Setting parameters and arguments5m 29s
-
(Locked)
Returning values from functions4m 45s
-
(Locked)
Functions across languages3m 26s
-
(Locked)
Challenge: Favorite cities1m 2s
-
(Locked)
Solution: Favorite cities1m 48s
-
-
-