0% found this document useful (0 votes)
19 views1 page

What Is Python - 0005

Python is a widely used programming language that allows users to give precise instructions to computers. The document provides an example of a Python program that checks if a US citizen needs a new passport based on the year it was received. It emphasizes the importance of critical and logical thinking in programming and notes differences between Python versions 2 and 3.
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)
19 views1 page

What Is Python - 0005

Python is a widely used programming language that allows users to give precise instructions to computers. The document provides an example of a Python program that checks if a US citizen needs a new passport based on the year it was received. It emphasizes the importance of critical and logical thinking in programming and notes differences between Python versions 2 and 3.
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/ 1

Python is one of the most popular programming languages in the world.

We can use the python language


to give instructions to a computer to get it to complete tasks on our behalf. As you should expect,
computer programming languages differ from spoken and written human language. Take English for
example. The English language has a speci�c alphabet, dictionary of words, and grammatical / syntactical
rules for how we construct sentences and documents. However, the English language also has many
oddities and rule exceptions that make learning it complex. Thankfully, computer languages (Python
included) tend to be more precise, and there are less rule-exceptions that we need to worry about.

When we develop programs (or “code”) we are writing a sequence of precise instructions for the computer
to follow. As an example, take a look at the short python program below. This program is used to
determine if a US citizen needs to get a new passport or not. US passports are valid for 10 years after the
time it was created.

1 import time
2 current_year = int(time.strftime('%Y'))
3 received_year = int(input('What year did you get your passport? '))
4 if received_year + 10 < current_year:
5 print('You should go get a new passport')
6 else:
7 print('You may use your current passport')

If you do not understand what is going on with that code, have no fear! We have not actually covered this
material yet, I just wanted to get to show you some actual, real Python code that accomplishes something
useful. I’ll break down what is going on piece-by-piece:

• Line 1 is letting the computer know that we are going to need to get some information about time
• Line 2 asks the computer what the current year is and saves it by the name current_year
• Line 3 asks whoever is using this program to enter when he or she got the passport
• Line 4 checks if the passport is invalid, and if so alerts the user of this (line 5 ) and if not it uses the
alternate case (line 6 ) and tells the user the passport is still acceptable (line 7 )

What Python programming function is used to show some text to the person
interacting with the program?

strftime()

int()

print()

If you aren’t used to writing computer code, it may take some time to shift your brain into the right
mindset. Writing code requires us to think critically, logically, and in a step-by-step manner. Some of you
may not be used to thinking in this way, at least not for extended periods of time. In these early stages of
your programming career, try to be cognizant about the mindset that you are going to take when you begin
to code, but also don’t get stressed if it doesn’t come “naturally” from the get-go.

By the way, when we work with computer programs, it is often useful to have a text editor that has line
numbers, as shown in the example. This allows us to easily see how much code we have written, where
we are at in our code, and gives us a nifty way to refer to speci�c lines. Also, this lesson series is based on
Python version 3. If you �nd yourself searching the internet for python code, tutorials, or documentation,
you may encounter some code that is based on Python 2. Be careful of this, because there are a few
differences between these two major versions.

You might also like