0% found this document useful (0 votes)
4 views

Python Handbook

This document outlines the setup process for the CFI 2206 course, requiring the installation of Visual Studio Code and Python 3. It emphasizes the importance of understanding programming fundamentals, learning to apply new concepts, and utilizing online resources. Additionally, it provides instructions for writing simple programs that gather user input and display output, along with tips on variable naming and string formatting.

Uploaded by

Lethumusa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Python Handbook

This document outlines the setup process for the CFI 2206 course, requiring the installation of Visual Studio Code and Python 3. It emphasizes the importance of understanding programming fundamentals, learning to apply new concepts, and utilizing online resources. Additionally, it provides instructions for writing simple programs that gather user input and display output, along with tips on variable naming and string formatting.

Uploaded by

Lethumusa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

W01 Setup: Tools

Overview

Welcome to CFI 2206!

This week you will set up your computer with the applications you will use this semester. You
will need the following:

• Visual Studio Code - The application you'll use to write your programs.

• Python 3 - The application you'll use to run your programs.

Once you have those in place, you will be ready to write your first programs.

Preparation Material

One of the great things about programming in this day and age is that there is a wealth of
information available on the internet. In fact, professional programmers spend a good part
of their days looking for answers on the internet and then piecing them together and
modifying them to fit the specific problem at hand.

This means that to be a successful programmer you need the following:

1. A strong understanding of the fundamentals of programming (what you'll study in


this and subsequent courses).

2. The ability to learn and apply new things.

3. The ability to use information from various online sources.

This course and subsequent courses are designed to help you grow in all three of these
areas.

In this course, you will be provided the information you will need to be successful, whereas
in future courses you will develop your ability to find more and more of the information for
yourself. But even in this course, you will start to learn to use material from many different
sources on the internet. Some will be written by BYU-Idaho, but much of it will be curated
for you from various resources available on the internet.

Install Python and Visual Studio Code

you'll be downloading and install programs and an extension from:

• https://www.python.org/downloads/

• https://code.visualstudio.com/download

• https://marketplace.visualstudio.com/items?itemName=ms-python.python

Getting Help / Troubleshooting


You need to complete the setup of all of these tools to be successful in this course.

If you have questions or run into any problems, please post a message to WhatsApp

Submission

There is no submission required for this setup activity. You just need to ensure that you have
completed the steps above to be prepared for the upcoming activities.

Hint :

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.

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 :

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."

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 financial product, then allow them to type
in their financial product. Finally, have the program respond to them by displaying the text
"Your favorite financial product is" followed by the financial product they typed.

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

Please type your favorite financial product: Ecocash

Your favorite financial product is

Ecocash

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

Please type your favorite financial product: Mukuru

Your favorite financial product is

Mukuru

Notice that the program displays back the financial product that the user entered, so it is
different each time, depending on the financial product 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.

Variables
One of the things you learned in the previous lesson was how to store data in a variable. A
variable is like a name that we attach to that data, so that later we can refer to it when we
need it.

In your programs this week, you are going to start to see many variables used
simultaneously in the same program. This is very common, and doesn't cause any problem
for the computer. As long as you are consistent and always use the same name for the same
data, you won't have any problems.

Because we will have to keep track of more and more variables, it becomes increasingly
important to choose good names for them. For example, while you may remember
what x means now, in a few weeks, months, or years, you might forget. On the other hand a
variable name like color or even favorite_color is much more descriptive and will help you
and others better understand your code.
Hint :

You can't use spaces in variables, so if you want a long variable name with multiple words,
the Python style is to use underscore characters between the words, such
as: this_is_a_very_long_variable_name .

Other style guides, especially for other languages may use different approaches, such as
"camel case" where each subsequent word is capitalized, such
as thisIsAnotherLongVariable, but in this class, you should stick with the underscore, or
"snake case," approach.

Comments

Comments are a way for you to include notes in your code. They don't affect the program in
any way, but they make it easier for someone to understand the code when they look at it
later. To add a comment to your code, include the # sign before the text that you want to be
a comment.

Combining and Formatting Strings

As you learned in the previous lesson, "Strings" are variables that are a sequence of
characters (for example, letters, numbers, spaces, symbols, etc.).

s shown in these videos, some helpful string methods available in Python are:

Code Result

words = "the GLORY of GOD is intelligence" the GLORY of GOD is intelligence

words.capitalize() The glory of god is intelligence

words.title() The Glory Of God Is Intelligence

words.upper() THE GLORY OF GOD IS INTELLIGENCE

words.lower() the glory of god is intelligence

words.count("g") 1

words.lower().count("g") 3

Notice that words.count("g") resulted in a 1, because it did not count the two cases of
capital "G" in the sentence. On the other hand, words.lower().count("g") resulted in a 3,
because it first converted everything to lowercase, and then counted them, so when it
counted the g's, the capital G's in that sentence were first converted to lowercase g's, and
then they were counted.

Hint

The examples in this table all say "words." but the name "words" is not special. In this
case, it assumes that the string is stored in a variable named words but it could have been
any variable name such as: first_name.title() or book_title.capitalize().

Activity Instructions

Overview

An iconic line from the James Bond movies is that he would introduce himself as "Bond,
James Bond." For this assignment you will write a program that asks for your name and
repeats it back in this way.

Instructions

Prompt the user for their first name. Then, prompt them for their last name. Display the text
back all on one line saying, "Your name is last-name, first-name, last-name" as shown:

What is your first name? Scott

What is your last name? Burton

Your name is Burton, Scott Burton.

What is your first name? Brigham

What is your last name? Young

Your name is Young, Brigham Young.

Make sure to be precise! You should have the spacing, comma, and period appear exactly as
shown in the examples.

Adjust the Capitalization

Now that the program is displaying the strings back with the correct spacing, improve your
program by making it display the words using the .title() function on each variable so that it
capitalizes only the first letter and all the other letters are lowercase.
Test that your program works by trying some words that are capitalized and some that are
lower case. The output should be the same. For example:

What is your first name? Sindy

What is your last name? Moyo

Your name is Sindy, Sindy Moyo.

What is your first name? sindy

What is your last name? MOYO

Your name is Sindy, Sindy Moyo.

What is your first name? siNdy

What is your last name? MOyo

Your name is Sindy, Sindy Moyo.

You might also like