Q&A
Q: are booleans just
True
/False
?
A: Yes! It may (at this point) seem silly to have a whole variable type with only two possible values as options…but we’ll quickly see how helpful these are when programming!
Q: wtf is a party cup???
A: It’s a plastic cup that tends to be red that people often give out at parties for their guests to drink in. It’salso known as a red solo cup. (There’s a whole country song about them.) They were pervasive when I was in college…but I’m not realizing (as a few people asked this) that they may not be anymore…things you don’t think of when you come up with these metaphors! You can just think of them as a plastic cup.
Q: Is Python similar to R?
A: In many ways, yes! I often say that nearly anything you can do in R you can do in Python and vice-versa. But, the goals behind the programming languages are different. R was developed by statisticians for statisticians (originally) so it thrives at interacting with, analyzing and visualizing data (but is capable beyond that)! Python was developed as a general-programming language, so while it also has the capability to interact with data, it’s not strictly designed for that. (For example, the DataFrame object in R is a first-class citizen, but python does not natively have any objects like DataFrames.)
Q: Are the exams throughout the quarter going to be digital, on our computer, or will they be on paper testing us conceptually? Excited for this course!
A: They will be on a computer, taken at the TTC-CBTF (in AP&M B349…that’s in the basement). They will focus on concepts, code reading, and code debugging. You will not be expected to write a whole bunch of code from scratch (as you won’t have access to ChatGPT/your notes). See more discussion here: https://cogs18.github.io/assets/intro/syllabus.html#exams-38
Q: Are there any websites where we can practice coding projects and visually see our work being produced?
A: One great place to visualize intro-level python code is https://pythontutor.com/, developed by our very own Philip Guo!
Q: Will we be learning more about white space
A: Yes! A bit today and much more as we get into functions.
Q: are there other variable types we did not cover?
A: Yes! There are many. We’ll be introducing a few additional types very soon (lists, tuples, dictionaries) and others in a few weeks (arrays, DataFrames). We’ll also discuss how to create our own “types” of varibles in week 7/8. However, while we’ll cover the main variable types there are many we won’t cover in this class that are beyond the scope of an intro-level course.
Q: when it comes to the headings does the number of # matter?
A: That just controls the size of the header. An H1 (#) will be bigger than an H2 (##) header, for example.
Q: do we need assignment names when creating a string because the hw made it seem like we don’t need to assign the string to anything?
A: Any time you want to store a value for use later, it needs to be assigned to a variable. However, the value on its own can exist…it just can’t be referenced later.
Q: i didnt quite understand what assert was
A: Anassert
statement is something we’ll put in Jupyter Notebooks for you to help let you know you’re on the right track with a question. The way they work is that whatever comes after the wordassert
is something we expect to beTrue
. If that’s the case, when you run theassert
cell, you should get no output…or, as we say, it will “pass silently”. However, if your code is not behaving as we expect, it would give you an assertion error, letting you know that what we expected to be true is not true….encouraging you to revisit your code and try again. (These will also be discussed in lab this week, so encouraging attendance.)
Course Announcements
Due this week:
VQ3 due Wednesday
CL1 due Friday (labs start tomorrow!)
Pre-course assessments (two surveys) due Sunday
Notes:
Discuss: PL order and question variants
A1 has been released (discuss: notebook, LLM focus)
Office Hours listed on Canvas Homepage
Extra Help on Tues 4-5
Operators#
assignment
math
logic
comparison
membership
Assignment Operator#
my_var = 1
Math Operators#
+
,-
,*
,/
for addition, subtraction, multiplication, & division**
for exponentiation &%
for modulus (remainder)//
for floor division (integer division)
Logical (Boolean) operators#
use Boolean logic
logical operators:
and
,or
, andnot
Booleans are named after the British mathematician - George Boole. He first formulated Boolean algebra, which are a set of rules for how to reason with and combine these values. This is the basis of all modern computer logic.
and
: True if both are trueor
: True if at least one is truenot
: True only if false
Comparison Operators#
==
: values are equal!=
: values are not equal<
: value on left is less than value or right>
: value on left is greater than value on right<=
: value on left is less than or equal to value on right>=
: value on left is greater than or equal to value on the right
Activity Time#
Complete all questions in this Google Form (https://forms.gle/9vmzUC3Uu88JaXQm9) and then click submit.
You are encouraged to:
Talk with your neighbor
Try the questions out in your notebok to check your understanding
If you have questions, I’m happy to come over as we work on this!
Write a Python expression that uses some combination of logical/boolean and comparison operators that will store the value False in the variable false_var.
# cell included to test code out for the activity!
modulo_time = 4 * 2 % 5
modulo_time
3
false_var = (5 > 10) and (3 == 3)
false_var
False
TRUE and TRUE
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[7], line 1
----> 1 TRUE and TRUE
NameError: name 'TRUE' is not defined
sword_charge = 90
shield_energy = 100
(sword_charge >= 90) and (shield_energy >= 100)
True
Membership Operators#
Membership operators are used to check whether a value or variable is found in a sequence.
Here, we’ll just be checking for value membership in strings. But, we’ll discuss lists, tuples, sets, and dictionaries soon.
in
: True if value is found in the sequencenot in
: True if value is not found in the sequence
x = 'I love COGS18!'
print('l' in x)
True
print('L' in x)
False
print('COGS' in x)
True
print('CSOG' in x)
False
print(' ' in x)
True
String Concatenation#
'COGS' + ' 18'
'COGS 18'
'a' + 'b' + 'c'
'abc'
Code Style: Operators#
Single space around operators
No spaces after leading parentheses or before trailing parentheses