INF 1511 VISUAL PROGRAMMING CH 1 Flashcards

CHAPTER 1

1
Q

Create a variable monthly_savings, equal to 10 and num_months, equal to 4.
Multiply monthly_savings by num_months and save it to new_savings.
Add new_savings to savings, saving the sum as total_savings.
Print the value of total_savings.

A

Create the variables monthly_savings and num_months
monthly_savings=10
num_months=4

Multiply monthly_savings and num_months
new_savings = monthly_savings * num_months

Add new_savings to your savings
total_savings = savings + new_savings

Print total_savings
print(total_savings)

Multiply monthly_savings and num_months
new_savings = monthly_savings * num_months

Add new_savings to your savings
total_savings = savings + new_savings

Print total_savings
print(total_savings)
140

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

Create a new float, half, with the value 0.5.
Create a new string, intro, with the value “Hello! How are you?”.
Create a new boolean, is_good, with the value True.

A

Create a variable half
half=0.5

Create a variable intro
intro=”Hello! How are you?”

Create a variable is_good
is_good=True

Create a variable half
half=0.5

Create a variable intro
intro=”Hello! How are you?”

Create a variable is_good
is_good=True

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

define python programming langauage

A

it is a powerful high level, interpreted, interactive, dynamic object oriented programming language

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

what is a high level programming language vs low level

A

is designed to simplify computer programming and make it more accessible to humans. closer to human languages and further from machine languages
-low level is closer to binary code

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

interpreted vs compiled and transcompile and what is it used for

A

this is how a computer executes code

-INTERPRETED Languages: These languages (e.g., Python, Ruby, JavaScript) are executed directly by an interpreter without prior compilation. the source code is not directly translated by the target machine. Instead, a different program, aka the interpreter, reads and executes the code. therefore, it supports a complete debugging and diagnostic environment making the job of fixing mistakes much faster. Also, the software development is quite rapid and flexible in it.

-Compiled Languages: Code is transformed into machine code (executable) before execution. Examples include C, C++, and Java.
compiled language, the target machine directly translates the program.

-Transcompile Languages: These languages convert source code from one language to another (source-to-source translation).

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

what is interactive or dynamic

A

-An interactive programming language is a type of language that allows developers to interact directly with the program as they write it

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

REPL

A

Read ,evaulaute print loop
Allows you to run Python code interactively while working on a project or learning the language. This tool is available in every Python installation, so you can use it at any moment.

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

What are the features of python

A

-Python is easy to learn
-It has easier to read syntax.
-It uses white space
-Python is free. open-source model.
-Python can be integrated with other languages
-Python is an interpreted language
-Python is a good choice for web development, networking, games, data processing, and business applications
-For efficient memory management, Python uses garbage collection,
-Python supports exception handling

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

What is script or scripting

A

python can do RAPID APPLICATION DEVELOPMENT.
A SCRIPT usually consists of a few lines of codes, and it solves a very specific problem. automate small tasks extract info from a set of data manipulation of files and directories scrape data from a website

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

Mutable Data Types

A

Data types in python where the value assigned to a variable can be changed
eg.list ,set, dictionary,bytearray

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

Immutable Data Types:

A

Data types in python where the value assigned to a variable cannot be changed
eg .numeric(integers,floats complex) ,string, tuple,range

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

what code to use to see data type of a variable IE BOOLEAN ,INTEGER ,STRING

A

Type ( ) insert the object into the bracket

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

LITERALS in Python

A
  • is defined as the raw data assigned to variables or constants while programming.
    -We mainly have five types of literals which includes string literals, numeric literals, boolean literals, literal collections and a special literal None.

A literal is a number or string that appears directly in a program. The following are all literals in Python:

10 # Integer literal

10.50 # Floating-point literal

10.50j # Imaginary literal

eg.Variable eg X=10 (the entire thing is a variable)

Literal is 10

Identifier is set by ‘programmer user’ which means the same as ‘python keyword’ eg the ‘X”

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

explain what is a identifier

A

-A Python identifier is a name used to identify a variable, function, class, module or other object.
-An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores and digits (0 to 9). ——-Python does not allow punctuation characters such as @, $, and % within identifiers
-Cannot start with a number
-it is the same as the keword used by python but called a variable which the programmer assigns

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

what is a variable

A

Variables are used for storing data in a program.

To set a variable, you choose a name for your variable, and then use the equals sign followed by the data that it stores.

Variables can be letters, numbers, or words. For example,

1 = 10

length = 10

length_rectangle = 10.0

k=”Hello World!”

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

how many keywords are there

A

35
all in lowercase except for true and false

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

list the keywords first 10 a-d

A

and as assert async await break class continue def del

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

list the keywords second 11 e-i

A

elif ,else except finally for from global if import in is

19
Q

list the keywords last 11 L- Y

A

lambda nonlocal not or pass raise return try while with yield

20
Q

final 3 in capitals keywords

A

False

None

True

21
Q

what are comments and how to does it work in python

A

-Comments are the lines that are for documentation purposes and are ignored by the interpreter.

-The comments inform the reader what the program is all about.

-A comment begins by a hash sign (#).
-All characters after the # and up to the physical line end are part of the comment.

22
Q

A ………………. is a line that you see in a program.

A

Physical line

23
Q

A ………………… is a single statement in Python terms.

A

logical line

24
Q

When a ………………… is too long to fit on a single line, you can join two adjacent ………………into a ……………… by ensuring that the first………………. has no …………. and ends with a ………………………..

A

statement
physical lines
logical line
physical line
comment or #
backslash ()

25
Q

Python also joins adjacent lines into one logical line if an open ……………or ……………., or …………………is not closed.

A

parenthesis ( ( )
bracket ( [ )
brace ( { )

26
Q

type the code for the output.
my_list = [
‘apple’,
‘banana’,
‘cherry’,
‘date’
]

A

print(my_list)
[‘apple’, ‘banana’, ‘cherry’, ‘date’]

27
Q

type the code for the output.?
my_list = [
…: ‘apple’
…: ‘banana’
…: ‘cherry’
…: ‘date’
…: ]

A

print(my_list)
[‘applebananacherrydate’]

you cannot use strings across multiple line without ““closing commas on each string

28
Q

type the code for the output.?
long_string = ‘This is a very long string that ‘ \
‘spans multiple lines using a backslash.’

A

print (long_string)

This is very long string that spans multiple lines using a backlash.

Normal spaces

29
Q

type the code for the output.?
total_sum = (5 + 10 + 11 +
20 + 2)

A

print (total_sum)

                   48
30
Q

type the code for the output.?
print(“Initial\nCommit”)

A

Initial
Commit

prints on 2 physical lines

31
Q

type the code for the output.?
g = “"”geeks
for
geeks”””

A

print(g)
geeks
for
geeks

32
Q

type the code for the output.?
print(1,2,3,
…: 4,4,5,6,)

A

1 2 3 4 4 5 6

33
Q

type the code for the output.?
print(123
…: 45466)

A

Cell In[32], line 1

print(123 

      ^ 

SyntaxError: invalid syntax. Perhaps you forgot a comma?

34
Q

type the code for the output.?
print(1234,56565)

A

1234 56565
comma makes a space

35
Q

type the code for the output.?
print(1234,
…: 56455)

A

1234 56455

36
Q

type the code for the output.?
print(1234+
…: 4466)

A

5700

37
Q

type the code for the output.?
print(1234 + 1)

A

1235

38
Q

type the code for the output.?
print (1,
…: 2,
…: 3,
…: 4,
…: 5,
…: 6,
…: )

A

1 2 3 4 5 6

39
Q

Which function is used to show messages and results of computations?

A

print ( )

40
Q

print([“message”][variable list])

where …………… is the text string enclosed either in single or double quotes.

The ………… may be one or more variables containing the result of computation.

A

message
variable list

e.g print (“Hello World!”)

print (10)

41
Q

what is the code used to suppress newline character

A

,end’’

make sure the quotes are properly defined.

42
Q

type the code for the output.?

print(“Hello World!”, end=’’)
print(‘It might rain today’)

A

Hello World!It might rain today

43
Q

type the code for the output.?
print(‘Hello World!’, ‘It might rain today’)

A

Hello World! It might rain today

44
Q

type the code for the output.?
-Assuming the values of variables l and b are 8 and 5
-print (“Length is “, l, “ and Breadth is “, b)

A

l=8 b=5

print (“Length is “, l, “ and Breadth is “, b)

Length is 8 and Breadth is 5