Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 3 out of 29 pages
Class notes

Computer Programming Term 1 Python Study Notes (Syntax, Loops, & Data Structures)

Document preview thumbnail
Preview 3 out of 29 pages

Description: Master your introductory computer programming and Python courses with these clear, highly detailed study notes! Covering everything from basic command-line navigation and data types to advanced loops, string manipulation, and dictionaries, this guide is built to help you ace your exams and debugging assignments. What's Covered:Programming Fundamentals: Syntax vs. semantics, variables, dynamic typing, explicit/implicit type conversions, and core operators. Control Flow & Logic: If-else statements, elif chains, boolean logic, and relational/logical operators (and, or, not). Loops & Iteration: while loops, infinite loop prevention, for loops, the range() function, and nested loops. Functions & Algorithms: User-defined functions, the def keyword, code tracing, trace tables, and algorithmic efficiency. Strings & Data Structures: String geometry, slicing, .format() templating, lists, and dictionary operations. Stop spending hours debugging syntax errors and get a clean, reliable study guide. Download your copy today and boost your grade!

Content preview

Main Idea Explanation Examples

So what this would show here is that
Loops give us the count = 0
ability to the loops can repeat blocks of code
repeat blocks of based on certain conditions for an while count < 3:
code based on a exact number of times. print("I love python!")
certain condition, count += 1
or for an
exact number of While loop is similar and it would (they will count it less than 3 and 0
times. contain a certain condition on whether
and print i love python and will only
count 1 if it is + = and so that is
the code inside the loop will run or
The while loop what this code shows and on how it
not?
works very can be demoed for here)
similarly to If true then it will keep repeating
an if. while True:
A certain condition city = input("Please enter a city
controls whether name: (Nope to end) ")
the code inside of It will keep repeating checking the if city == "Nope":
it will run or not. condition each time after the code break
While the print("Oh! " + city + " is a cool
condition is true, spot.")
the code Four main parts of the loop all revolve
will keep repeating (if the code is true then it will input
around the control variable
- checking the the city to enter a name but it will
condition each not unless if a break and it will bring
time after the Oh!, city, is a cool spot and so that
code We initialize the control variable, is what this code would do.)
runs. create a while loop with condition
using control variable, code should The control variable needs to
his code will run if true, it would then update the be initialized before the loop.
output the word control variable for here. The keyword while
Hello 5 times: makes our while loop,
CS Python followed by our Boolean
Fundamentals — conditional: num < 5.
Unit 4
num = 0 Indented in the while loop is the
while num < 5: code that will
print("Hello") run - we print "Hello".
num += 1
num += 1 will increment our
There are four control variable by 1. This part
main parts of a keeps track of how many
while loop, and times the loop has iterated or
most of them repeated. After this line, we
revolve around loop back up to the while
what is known as and recheck our condition.
the control

,variable. # Initialize variables
total_sum = 0
The four basic count = 0
parts of our loop:
1. Initialize our print("Enter numbers to add to the
control variable running total.")
2. Create a while print("The program stops when the
loop with a sum exceeds 200.")
condition that
uses the control while total_sum <= 200:
variable try:
3. Code that # Prompt the user for input
should run while user_input = input("Enter a
the number: ")
condition is true
4. Update the # Convert input to a number
control variable (integer for this example)
number = int(user_input)

# Update the sum and the
count
total_sum += number
count += 1

except ValueError:
# Handle cases where the user
enters non-numeric input
print("Invalid input. Please
enter a valid integer.")
continue

# Output the results once the loop
condition (sum > 200) is met
print("") # Print a blank line for
readability
print("Sum:", total_sum)
print("Numbers Entered:", count)



name = input("Enter a name (STOP
Count Variable - Iterate = repeats to end): ")
Counts how many c=0
times the loop
runs or iterates. A count variable can check how while name != "STOP":
many times the loop runs or repeats c += 1
This is the code itself basically print("You entered " + name)
used in the name = input("Enter a name
example: (STOP to end): ")

, The code is used here and the name
name = always loops and runs, uses variable print("You entered " + str(c) + "
input("Enter a c to control the loop, and c+=x is names.")
name (STOP to used to go by increments of
numbers, After a name typed in this
end): ") (what this code would use would be
loop it will count the name and
c=0 reprompt them into that loop,and that it would show here that once
while name != STOP is obvious not to count it. you enter a name it will stop that
"STOP": name and make it different and so it
c += 1 would just stop the name in a way
print("You entered and so that is what this code shows
A sum variable is basically where it is
" + name) a count variable where it keeps a
here overall as a whole.
name = summary of how long they have ran
input("Enter a for and stuff and so that is what is And also it just shows as the name
name (STOP to shown here for the sum variable. was entered for here and so that is
end): ") what the result of this code would
print("You entered be.
" + str(c) + "
names.")


Name = loop runs

Variable c- is used
to control the loop

c+=1: goes by the
increments of the
names and is
needed to count
how many times a
user enters a
name

After they type a
name, it
enters the loop
and we
count that name.
Then we
reprompt them in
the loop.

STOP - not a
name and should
not be counted

c+=1: is at the
beginning of a
loop is because it

Document information

School year
3
Uploaded on
August 28, 2026
Number of pages
29
Written in
2025/2026
Type
Class notes
Professor(s)
Computer programming term 1 notes.
Contains
All classes
$5.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
0
Followers
0
Items
13
Last sold
-



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions