Podcast
Questions and Answers
Which of the following is the primary focus of computer science?
Which of the following is the primary focus of computer science?
- Analyzing algorithms and developing new software architectures. (correct)
- Providing computing solutions for businesses.
- Managing hardware infrastructure and trained personnel.
- Facilitating planning and decision-making in organizations.
Information systems primarily focus on the theoretical aspects of algorithms and programming languages.
Information systems primarily focus on the theoretical aspects of algorithms and programming languages.
False (B)
What is the role of the CPU in a computer?
What is the role of the CPU in a computer?
The CPU executes operations and processes data.
A ______ programming language is designed to be easily understood by humans.
A ______ programming language is designed to be easily understood by humans.
Match the following terms with their descriptions:
Match the following terms with their descriptions:
Which of the following is a characteristic of a compiler?
Which of the following is a characteristic of a compiler?
Volatile memory retains data even when the power is turned off.
Volatile memory retains data even when the power is turned off.
Define 'portability' in the context of programming.
Define 'portability' in the context of programming.
In Python, the ______
function is used to display output to the console.
In Python, the ______
function is used to display output to the console.
What is the purpose of the def
keyword in Python?
What is the purpose of the def
keyword in Python?
The eval()
function is generally recommended for handling user inputs because it is secure and prevents malicious code execution.
The eval()
function is generally recommended for handling user inputs because it is secure and prevents malicious code execution.
What is the difference between regular division (/
) and integer division (//
) in Python?
What is the difference between regular division (/
) and integer division (//
) in Python?
The ______
symbol is used to return the remainder of a division operation.
The ______
symbol is used to return the remainder of a division operation.
Which of the following operations is known as 'concatenation' when working with strings?
Which of the following operations is known as 'concatenation' when working with strings?
In Python, you can only use double quotes to define a string.
In Python, you can only use double quotes to define a string.
Explain what a 'for' loop is used for in programming.
Explain what a 'for' loop is used for in programming.
In a 'for' loop, the ______ takes on successive values in the sequence.
In a 'for' loop, the ______ takes on successive values in the sequence.
What is the output of print(int(5.8))
in Python?
What is the output of print(int(5.8))
in Python?
The range()
function includes the end value in the generated sequence of numbers.
The range()
function includes the end value in the generated sequence of numbers.
What does the term 'string slicing' refer to in Python?
What does the term 'string slicing' refer to in Python?
Flashcards
Computer Science
Computer Science
The foundation of computing, studying what can be computed, and a fundamental approach to designing solutions.
Information Systems
Information Systems
A combination of hardware, software, infrastructure, and personnel used for planning, control, coordination, and decision-making.
Software
Software
Programs or instructions that control hardware.
Hardware
Hardware
Signup and view all the flashcards
CPU Role
CPU Role
Signup and view all the flashcards
Volatile Memory
Volatile Memory
Signup and view all the flashcards
Nonvolatile Memory
Nonvolatile Memory
Signup and view all the flashcards
High-Level Language
High-Level Language
Signup and view all the flashcards
Low-Level Language
Low-Level Language
Signup and view all the flashcards
Syntax
Syntax
Signup and view all the flashcards
Semantics
Semantics
Signup and view all the flashcards
Compiler
Compiler
Signup and view all the flashcards
Interpreter
Interpreter
Signup and view all the flashcards
String Repetition
String Repetition
Signup and view all the flashcards
String Concatenation
String Concatenation
Signup and view all the flashcards
Simple Assignment
Simple Assignment
Signup and view all the flashcards
Simultaneous Assignment
Simultaneous Assignment
Signup and view all the flashcards
For Loop
For Loop
Signup and view all the flashcards
Integer Division
Integer Division
Signup and view all the flashcards
Remainder Division
Remainder Division
Signup and view all the flashcards
Study Notes
- Gutxi Van Buuren is the name of the recitation TA
Computer Science vs. Information Systems
-
Computer science is a foundation to computing and studies what can be computed
-
Involves designing solutions, algorithm analysis, and experimentation
-
Examples include mobile computing, AI, networking, and databases
-
Information systems coordinate hardware, software, infrastructure, and personnel
-
Facilitates planning, control, coordination, and decision-making in organizations
-
Example: mobile banking
-
Computer science concentrates on:
-
Algorithms
-
Programming languages
-
New software architectures
-
Techniques for complex problem-solving
-
Information systems focuses on providing computing and networking solutions, for employees and customers, that achieve corporate goals
Software vs. Hardware
- Software consists of programs or instructions that control hardware
- It's developed through programming.
- Hardware is the physical machine
- PC, tablet, and smartphone are all examples
CPU (Central Processing Unit)
- The CPU is the "brain" of the computer Fetch, decode, and execute instructions are the steps performed repeatedly by the CPU
- Operations are executed by the CPU
- Memory processes and stores data
Memory
- Volatile memory loses information when power is removed.
- Nonvolatile memory (internal hard drive, secondary memory) retains information in the absence of power
- Volatile memory does not save when turned off, but nonvolatile memory does
High-Level vs. Low-Level Programming Languages
- High-level languages are designed to be understood by humans (e.g., Python).
- Low-level languages are understood by machines/computer hardware
- Represented by "zeros" and "ones."
Syntax vs. Semantics
- Syntax is the form of the code, including punctuation and parentheses
- Semantics is the meaning of the code (e.g., a
print
statement)
Compiler and Interpreter
- Compiler: Translates complete programs into machine code before execution, resulting in faster code running
- Interpreter: Executes code line by line during program run
Portability
- The exact same program executes on different machines
Programs
- Print statements are to display a value:
print("Hello World")
displays "Hello World"print(2+3)
displays 5- To define a function, start the program with
def
For Loop Function
- Syntax:
for <variable> in <sequence>:\n<body>
var
is the variable (usuallyi
)sequence
is a list of values or range of values.- Example:
for i in [0, 1, 2, 3]:\nprint(i)
would output 0, 1, 2, 3 for i in range(5):\nprint(i)
would output 0, 1, 2, 3, 4for i in range(2,6):\nprint(i)
would output 2, 3, 4, 5
Step Function
for i in range(1,10,2):\nprint(i)
outputs 1, 3, 5, 7, 9
Software Development Process
- Thinking is the most important thing to do, before you code
Temperature Conversion Program
- Defines a function to convert degrees Celsius to Fahrenheit
Print command
\n
represents a new line.end =""
is the general format for print function
Inputs
Eval
should be avoided for security reasonsInt
represents an integer, which is a whole number with no decimal point>>>int(5.8)
results in 5Float
represents a floating-point number, which is a number with a decimal point- >>>float(5)
results in 5.0`- Floating point numbers are approximations.
Mathematical Expressions (Division)
- "Regular" division:
- Uses the
/
symbol. - Always returns a float
- Example: 5/6 results in 0.8333333333334
- "Integer" division:
- Uses the
//
symbol - Returns the quotient without the remainder (rounds down to the nearest integer)
- Example: 5//6 results in 0
- "Remainder" division:
- Uses the
%
symbol - Returns the remainder of the two numbers inputted
- Example: 7%3 results in 1
Strings
-
"Concatenation and Repetition"
-
Strings are textual sequences of characters
-
You can use single or double quotes
-
Concatenation joins strings using
+
-
Ex:
str1="Hello"\nstr2="World"\nprint(str1 + str 2)
will printHelloWorld
-
Repetition repeats a string multiple times using
*
-
Ex:
str1="Hello"\nprint(str1*3)
will printHelloHelloHello
Simple and Simultaneous Assignments
- Simple assignment:
<variable>=<expression>
<expr>
is evaluated to produce a value, which gets assigned to<variable>
- Textual input:
<variable> = input(<prompt>)
- Numerical input:
<variable>=eval(input(<prompt>))
Eval
is required when you want a number
- Simultaneous assignment:
- Assigns values to multiple variables at the same time
Equal Sign Differences
=
(single) assigns a value to a variable.==
(double) asks if the 2 quantities are equal
For Loop
- Executes a sequence of statements a definite number of times
- General format:
for <var> in <sequence>:\n<body>
<var>
: Loop index (usuallyi
orj
)- Takes on the successive value in the sequence
<sequence>
: List of values or range of numbers.- Statements in the body execute one time per value
Range Function
- Takes the form
range(start value, end value, step size)
. - Example:
range(1,5,1)
produces 1, 2, 3, 4 - The end value is not included
- To include 5, use
range(1,6,1).
- When using range, the function definition is given using range(1, n+1) if the problem asks for an inclusive range.
range(0,11,2)
produces 0, 2, 4, 6, 8, 10
Math Operations in IDLE Shell
- Addition:
+
>>> 3+4
results in 7- Subtraction:
-
>>> 4-3
results in 1- Multiplication:
*
>>> 4*5
results in 20- Division:
/
>>> 23/5
results in 4.6- Floor Division or Rounded Division:
//
>>> 33//6
results in 5- Modular Division or Remainder:
%
>>> 33%6
results in 3- Exponent:
**
>>> 4**2
results in 16- Print a string on a new line use
\n
Print vs. Return
Print
displays what's in the string.Return
returns the value.
Def Main and Def Function
def main()
automatically executes/runs.def function_name()
only runs when you type the function
Iterating a For Loop
- Iterating can be done using
range
,string
, orlist
Using Range()
range()
function generates a sequence of numbersfor i in range(5):
loops from 0 to 4
Iterating Over a String
- A string is iterable, so you can loop through its characters.
- Example:
text = "Python"\nfor char in text:\nprint(char)
- Output:
P
y
t
h
o
n
Iterating Over a List
- Lists are also iterable, so you can loop through their elements
- Example:
fruits = ["apple", "banana", "cherry"]\nfor fruit in fruits:\nprint(fruit)
- Output:
apple
banana
cherry
Python
- Python division types:
- Regular division (6/4=1.5)
- Integer division (6//4=1)
- Remainder division (6%4=2)
Type Conversion and Rounding
- These conversions are
round
,int
, andfloat
int
andfloat
do not support getting multiple values in a single input- Example:
>>>round(6.789472,3)
is 6.790>>>int(3.9847)
is 3
Python Math Library
- Begins with use of
import math
for function from the library math.sqrt(49)
evaluates to 7.0 (square root function)
Accumulator
- Used in factorial calculations.
- Determines n! for n>=0.
- Error if user enters n<0.
range(1,n+1)
isrange(1,)
if n==0
Fundamentals of Binary Numbers
- To represent N=4 value amounts:
- Represents 2^N or 2^4 = 16 numbers.
- Largest positive number = (16/2)-1 = 7 = 0 -> 7
- Most negative number = -8
- To represent N=5 (byte) amounts:
16 positive
( 0 to 15)16 negative
(-1 to -16)`
Strings in Python
- Strings are textual data, allowing single or double quotes and are sequences of characters
>>>str1="Hello"
and>>>str2="spam"
print(str1, str2)
produces prints 'Hello span '>>>type(str1)
returns<class 'str'>
- In strings the general form uses indexing for selection of expressions in string
- Expression values determine which character is selected
- Indexing starts at 0
- To get the index from the right, use negative index Examples of indexing:
greet="Hello Bob"
012345678
>>>greet[0]
H
- Slicing is when you return a continuous sequence of characters
<string>[<start>:<end>]
- string operations are + for concatenation and * for repetition
- string includes indexing through
<string>[]
- string includes slicing though
<string>[<start>:<end>]
- string includes a function for length
len(<string>)
->>>len(spam)
gives 4 - strings iterates through characters useing
for <var> in <string>
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.