CSE 110: Introduction to Programming

W01 Learning Activity (1 of 2): Your First Program

The Basics of Writing a Program

We all interact with many kinds of devices, websites, and apps that are made from "programs." As you might imagine, apps such as Instagram or Google Maps are quite complex and have taken teams of professional programmers many months or years to create. You are starting on the journey that can lead to creating programs that are just polished and interactive, but we will begin with much simpler programs.

The essence of all programs, no matter how complex or simple, is that they provide a step-by-step list of instructions that the computer will follow. The computer, while powerful, is also very simplistic—it only does what you tell it. In addition, it does exactly what you tell it to do, nothing more and nothing less, and if you leave out a very small thing, or make even a tiny mistake, the computer is very unforgiving.

Starting with this activity, you are going to practice writing programs—the step-by-step instructions for the computer—and you are going to start with simple ones. You will start by displaying words on the screen and have the user type responses in a text window. While not nearly as glamorous as the professional apps you see around you, the fundamentals are the same. These simple programs will help you develop skills you need to create more powerful and more exciting applications as you continue to learn.

Hint from Instructor:

In programming, when we use the word "print," it means that the words will be displayed on the screen when the program is run—it doesn't have anything to do with actual "printers."

Please watch the following videos that introduce the idea of writing programs. While you are watching, you should pause the videos and follow along by typing the same code on your computer. The demos they walk through will be very similar to the assignments you have this week.

Direct link: Basic Print

Hint from Instructor:

When you run your program for the first time, you will see lots of other text in the window that displays messages from when Visual Studio Code started up. You don't need to worry about all of these messages. The important thing is to look at the bottom and see if your message displayed after all of this other text.

Direct link: Variables

Direct link: The Debugger

Direct link: Basic f-strings

Direct link: Input

Activity Instructions

For this activity you will write a program that uses both input (obtaining data from the user via the keyboard) and output (displaying data to the user on the screen).

Instructions

Write a program that asks a user for their favorite color, then allow them to type in their color. Finally, have the program respond to them by displaying the text "Your favorite color is" followed by the color they typed.

In the following example, the user types in "Blue" for their favorite color:


Please type your favorite color: Blue
Your favorite color is
Blue

In this example, the user types "Hot Pink" for their favorite color:


Please type your favorite color: Hot Pink
Your favorite color is
Hot Pink

Notice that the program displays back the color that the user entered, so it is different each time, depending on the color that was typed.

To make this program work, you will need to get input from the user and then save the data they provide into a variable. Then, at the appropriate time you print (i.e. display) the data stored in that variable.

Sample Solution

When your program is finished, please view a sample solution to this program to compare your approach to that one.

(Optional) Additional Supplemental Videos

The following videos are not required, but you are welcome to watch them if you would like additional information.

Submission

When you have completed all of the learning activities for this week, you will return to Canvas and submit the associated quiz there.

Up Next

Other Links: