Unit 1: Flashcards

1
Q

What is python named after?

A

You might think that it’s named after the snake, but it’s actually named after the comedy TV show “Monty Python’s Flying Circus!”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When did work on Python began in ____ and the current version that we’re using, ______, was released in _____.

A

Work in Python began in the 1980s and the current version that we’re using, version three, was released in 2008.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When you install Python on your computer, it comes with an application called “____” which is an abbreviation for __________ .This is where you _______.

A

When you install Python on your computer, it comes with an application called “IDLE”, which is an abbreviation for Integrated DeveLopment Environment. This is where you write your programs and it includes simple features like colouring your programs to show you what commands you’ve used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Does IDLE work the same on any kind of computer?

A

Yes, it works the same for a Mac or Windows Computer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the most important aspects of Python?

A

To make sure that the code written is readable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you make sure that the code written in Python is readable?

A

This is done by using white space, another word for indentation or the amount of space to the left of your code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What can you use Python to do?

A

Python is fun— what profession you might want to have in the future
Once you learn Python, you can start working with other tools like Raspberry Pi, for which Python is the main language.
you can add on to your Python skills with PyGame, a library for games made in Python.
Sci-fi is another library that helps with math, science and engineering research.
Big companies like Google, Yahoo, Disney and IBM and websites like Pinterest, New York Times and Instagram all use Python as a baseline for their organisations.
Python supports other languages, like the mapping system GIS , or Java and even C++

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to download python?

A

Visit the official python website
https://www.python.org/downloads/
Select the latest version
Click install and follow the instructions
Make sure you check the box that says “Add Python to PATH: at the bottom of the setup window.
Go to the window key and search for IDLE—> click open
Click on new file to type in your code and then click on run–> run module

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Take a look at the version of Python shown below, where the version is 3.9.4:

Python 3.9.4 (v3.9.4:1f2e3088f3, Apr 4 2021, 12:32:44)
[Clang 6.0 (clang-600.0.57)] on Darwin
Type “help”, “copyright”, “credits” or “license()” for more information.
»>
When you open up IDLE, is your installed Python version 3.X.X, where X can be any numbers?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What do you see and do when you’ve installed Python and opened it for the first time?

A

You should have a screen open that says on the first line “Python: and then the version number of what version of Python you have, followed by some other information. This is called the Python shell.
Always make sure that you have this (»> symbol) showing at the left part of the screen. This is called the prompt and it lets you know that Python is ready and waiting for you to do something.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the print command about and how do you code it?

A

The first command we’ll learn about is called the print command. This has Python print something inside the window.

To code this command
print (“….”) the …. Is what you are trying to say

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

This “print” is your first _______

A

This “print” is your first program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a program?

A

A program is a set of instructions or commands that tells the computer what to do.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to save and open programs?

A

With IDLE open, go to file and then new file.
Type your code. ( you should be toying your code in the space where there is no Python version and no arrow&raquo_space;> symbol in this window) One other way to tell that you’re writing (with the arrow prompt»> your code in the right place is that you see the Run command. If you’re in the shell window, you won’t have the Run command on your toolbar
Go to file and save
Go to run and then run module or hit F5 on your keyboard.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Can you save what you typed in shell?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you open an existing Python program file?

A
  1. Open IDLE
  2. Go to file and then Open…
  3. Navigate to where the file on your computer is and click Open.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How to edit an existing Python program?

A

Open an existing Python program file.
Make edits to the program and save the file.
Run the new program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How do you make edits to the program and save the file?

A
  1. Make your edits to the file.
  2. Make sure you are in the .py file window.
  3. Go to File and then Save or Save as…
19
Q

What is a comment?

A

A comment is for giving yourself or other programmers information about the code in way that won’t interfere with the program running. (It is to note down your thoughts so that you remember what you were thinking and your instructor can see what you were thinking)

20
Q

What are the two ways to write a comment in Python?

A

If you have just one line that you want to write, you can use the pound or hashtag # sign before the text.

If you want to write several lines of comments, you would put a hashtag # on each line.

21
Q

What does debugging mean?

A

Debugging means removing bugs or errors from your program since everyone makes mistakes and when we write a program, it may not be 100% correct the very first time. We may have errors in our code and the program may not run correctly/

22
Q

What is the first step in debugging?

A

The first step in debugging is to figure out which kind of error you are dealing with.

23
Q

What are the three main groups that errors can be classified in?

A

Syntax errors, Runtime errors and logical errors.

24
Q

What is syntax errors?

A

Syntax error is the most basic type of error. Syntax is like grammar, it is a set of rules that defines how a program is written. A syntax error happens when we do not follow the Python programming rules correctly.

25
Q

What is runtime errors?

A

Runtime errors: Even if your syntax is right, your program may exit unexpectedly during execution. This is due to errors in code that occur at runtime, We will some examples of these later in this tutorial.

26
Q

What are logical errors?

A

These errors are caused by a mistake in programming logic and are most difficult to fix because we don’t get any error message. We will see some examples of these types of errors in later units. These errors cause a program to product incorrect results but often do not crash.

27
Q

> > > print(“This is Python saying hi!)
SyntaxError: EOL while scanning string literal
Oops, we got a Syntax error! Can you spot the error? Do you see what’s missing?

Also, what does EOL stands for?

A

We forgot to add the quotation marks at the end of our statement. In Python, we can use single quotes (‘) or double quotes (“) to enclose a statement, but they have to be at the beginning and the end.

EOL stands for End Of Line which means Python is expecting a character at the end of line. Tip: Remember to check for ending quotation marks!

28
Q

> > > print(“This is Python saying hi!’)
SyntaxError: EOL while scanning string literal
What is wrong with this?

A

This time we used two different types of quotes and that’s why we got the syntax error. The type of quote used to open a string should be the same as the one used to close the string. We cannot mix quotations marks like above.
Tip: Whichever quotation mark you choose, make sure you are consistent with your style.

29
Q

> > > print “This is Python saying hi!”
SyntaxError: ___________

A

Missing parentheses in call to ‘print’. Did you mean print(“This is Python saying hi!”)?

The above error is raised when you try to print a value to the console without enclosing that value in parentheses. In Python 3, you must add parentheses around any statements you want to print to the console.

Tip: Remember Python’s syntax rule of including parentheses when calling the print function.

30
Q

What type of error is it if we type Print (with capital P) instead of print in our code? Why?

A

This type of error is called NameError which is an example of runtime error. NameError occurs when Python cannot recognise a name in your program. Python is case sensitive, therefore Print() with capital ‘P’ is not the same as print(), and there is no other function defined with the name Print. Python does not understand that we actually wanted to use the print() function.

Tip: Remember that Python is case sensitive and write your code accordingly.

31
Q

What type of error is it if we use square brackets instead of round brackets in the print function? Why?

A

We got a TypeError which is also an example of a runtime error. These errors occur when an incorrect data type is used. In Python, we use parentheses to call a function. The above error is raised when we try to use square brackets instead of round parentheses to call a function. In Python, square brackets are used to Denise a list data type. You will learn about these in later units.
Tip: Since print() is a function, it must use round parentheses and not any other type of brackets.

32
Q

What are the six things to take note/ some strategies that can help you debug effectively?

A
  1. Know what your code is supposed to do.
  2. Understand the syntax
  3. Structure the code so its easy to understand
  4. Use comments in your code.
  5. Fix the issues by looking at the description of each of the error you encounter
  6. Apply trial and error-try different ideas until you find what works best

We will talk more about debugging in upcoming units.

33
Q

How can you draw a car that looks like this
————-
_____//__]. [___\___
(O. |. -|. -|. O|
`_( )——————( )—-‘ on python?

A

use the print function to draw each layer

34
Q

How do you get this
Welcome to PyBank
Your one stop online Banking App!

Account NumberL 123-45-6789
Account Balance: $125.50

A

Add comment

#Purpose of this code
print(“Welcome to PyBank”)
print(“Your one stop online Banking App!”)
# Fill in your credentials
print (“ “)
print (“_ _ _ _ _ _ _ _ “)
print(“Account Number: 123-45-6789”)
print(“Account Balance: $125.50”)

35
Q

Indentation improves code readability. Which of the following is used in indentation?
Select one:
White space
Curly braces
Square brackets
Round brackets

A

White space

36
Q

Consider the following code. What caused the error?
»> print [“Hello, World!”]
Trace back (most recent call last):
File “ “, line 1, in
print [“Hello, World!”]
TypeError: ‘builtin_function_or_method’ object is not subscriptable

Select one:
Parentheses should be used, not square brackets.
Exclamation points are not allowed in Python.
Beginning and ending quotation marks do not match.
print is not the same as Print.

A

Parentheses should be used, not square brackets.

37
Q

IDLE in the Mac computer system works differently than the IDLE for Windows computer system.
Select one:
True
False

A

False

38
Q

Which of the following Python programs is named correctly?
Select one:
hello.c
hello.py
hello.js
hello.txt

A

hello.py

39
Q

A __________ is a set of instructions that tells a computer what to do.
Select one:
Comment
Program
Prompt
Shell

A

Program

40
Q

Single line comments use the symbol…
Select one:
#
!
@
//

A

#

41
Q

______ is a Python library that helps with math, science and engineering research.
Select:
PyGame
SciPy
SciMath
Turtle

A

SciPy

42
Q

Which of the following is NOT true about Python?
* Choose all that apply.
Select one or more:
Python was named after a TV show.
Python is a case sensitive programming language.
Python uses curly braces, not indentation.
Python only works on Windows.
Python was named after a snake.
Python allows you to write comments in your code.

A

All of these statements are not true.
Python uses curly braces, not indentation.
Python only works on Windows.
Python was named after a snake.

43
Q

Which of the following will NOT cause a syntax error?
Select one:
Using Print instead of print
Confusing square brackets [ ] with parentheses ()
Forgetting an ending quotation mark
Using a pound or hashtag # to comment your code.

A

Using a pound or hashtag # to comment your code

44
Q

Consider the following code. What caused the error?
»> Print (“Hello, World!”)
Trace back (most recent call last):
File “ “, line 1, in
Print (“Hello, World!”)
NameError: name ‘Print’ is not defined
Select one:
Square brackets should be used, not parentheses.
Exclamation points are not allowed in Python.
Beginning and ending quotation marks do not match.
Print is not the same as print.

A

Print is not the same as print.