Docsity

Python Programming: Data Structures, Keywords, Variables, Operators, Control Structures - , Quizzes of Computer Fundamentals

Partial preview of the text

Download Python Programming: Data Structures, Keywords, Variables, Operators, Control Structures - and more Quizzes Computer Fundamentals in PDF only on Docsity!

Python Programming REVIEW

DA_401/501/CSC 430_ Spring 2024

Mid-Term On next Wed (March 3) Lecture Time

 (^) Part I Closed-book, Paper pencil part (60%. 60 Minutes)  (^) Part II Open book, Coding part (40%, 90 Minutes) 

Accommodations?

Mid-Term Next Lecture Time

Common Program Concepts (not only python)

Common concepts:

  • (^) Key words
  • (^) Operators
  • (^) Punctuations
  • (^) Strict syntactic rules.

Keywords reserved for Python

Variables

Name:

◦ (^) case sensitive, ◦ (^) Valid names: letters and numbers, _, no space, no special symbol, not start with a number, (no keywords, be meaningful). 

Types:

◦ (^) Integers: x = 10 ◦ (^) Floating: pi = 3. ◦ (^) String: name = “I’m a student”, empty =““ ◦ (^) Boolean: quit = True, play = False

 Arithmetic

◦ Numerical: +, -, *, **, /, %, //

◦ Precedence: “pemdas,

◦ The assignment operator =: always last

 Comparison Operators ◦ (^) <, <=, >, >=, ==, !=  Logical Operators:

◦ and, or, not (year%4 == 0 and year%100 !=0) or year%400 == 0

Operators:

For example:

◦ (^) if: for exceptional ◦ (^) if-else: for two choices. ◦ (^) If-elif-else: for many choices ◦ (^) Nested if: there are conditional choices inside of any condition Applications

while (Boolean expression): statements

need to setup when the loop terminates

while True:

if count > 10:

break

count += 1

print("Hello Python")

While Loop

 (1) by range(start, stop, step) for num in range(10, 1, -2): print("num=", num)  (2) loop over a list list_1 = [1, 3, 5, 7, 9] for i in list_1: print(i)  (3) loop over a string word = "python" for letter in word: print(letter, end = “ ") # p y t h o n For loop: through a sequence

Nested Loops

 A for loop: ◦will “do” something to everything  A while loop: ◦ (^) will “do” something until a condition is not true.  Exchangeable Comparison: while vs. for

Sequence and Collection of

DATA

Comparisons

range(start, stop, step)

  • (^) start: 0 by default
  • (^) stop: not inclusive
  • (^) step: 1 default

for i in range(0, 10, 2):

print(i, end = “ “)

Range