Lecture 4: Functions and Conditionals
Craig Zilles (Computer Science) September 20, 2019 https://go.illinois.edu/cs105fa19
CS 105 Lecture 4: Functions and Conditionals Craig Zilles (Computer - - PowerPoint PPT Presentation
CS 105 Lecture 4: Functions and Conditionals Craig Zilles (Computer Science) https://go.illinois.edu/cs105fa19 September 20, 2019 Are you sitti ting next t to someone to talk to for th the clicker questi tions? To Today I'm using:
Craig Zilles (Computer Science) September 20, 2019 https://go.illinois.edu/cs105fa19
2
some of it?
confuses me most as of right now. I kind of understand why I need to do what I need to do in coding, but I am still foggy as to where each and every little character goes, and what makes something a syntax error and what doesn't.
3
4
What is the value of the above expression? A) 'a' B) 'b' C) 'c' D) 'd' E) 'e'
5
using recipes in recipes
6
def get_input_and_print(): name = input("Your name?\n") print("Hello " + name + "!")
get_input_and_print()
7
to me. I don't understand when to indent something, or what to return and when.
indentations stand for in Python.
8
9
Code Block A Code Block B (Execution determined by control flow construct) Control flow construct: Code Block C (Same indentation as A)
10
def test(): print('first') print('second') test() def test(): print('first') print('second') test() def test(): print('first') print('second') test()
11
first first second second first first second
def test(): print('first') print('second') test()
def welcome_message(first, last): message = "Welcome " + first + " " + last message += " to CS 105!" return message welcome_message("Harry", "Potter")
12
def f(x): return 3 * x What value is returned by f(f(2))? A) 3 B) 6 C) 9 D) 12 E) 18
13
when you don't have the return statement.
function to return the value of "none"?
something like this by accident: x = print("hi there!")
14
my_list = [0, 1, 2, 3] my_list.append(22)
len(my_list)
15
16
A) hours_spent < 6 hours B) 6 hours <= hours_spent < 9 hours C) 9 hours <= hours_spent < 11 hours D) 11 hours <= hours_spent < 13 hours E) hours_spent >= 13 hours
17
18
19
them, why they're used, etc.
20
21
22
Suppose young is a Boolean variable why does if young == true: not work when if young does?
23
letters?
thing1.lower() < thing2.lower()
24
if "hello":
25
with this concept.
then you can go out."
and
not
26
when it has both Boolean operators and other kinds of
'and' or 'or' to a symbol, it is hard to tell which one i should evaluate first.
x == 7 and y == 3 or x > 12 and y < -12
27
28
True or anything() is True False and anything() is False
(len(my_str) > 10) and (my_str[10] == 'a')
29
30
hello there hello there
print('hello') and print('there')
statements or if-elif-else.
chapter can be used in real world cases. A thing I like to do to help me better grasp the concepts, is imagine them happening in this world. So giving me more mundane scenarios of where we would be using these things would help a lot.
31
Asked my TA to send email to all students in the class that didn't take Exam 0.
if student in exam0_takers: send_email(student)
32
Company sends recruiting invitations to students with Python in their resume, sends 'nack' email to others if 'python' in resume.lower(): send_invitation(student) else: send_polite_decline(student)
33
Final exam location based on first letter of netid: [a-j] Loomis 100 [k-o] DCL 1320 [p-z] English 214
first_char = netid.lower()[0] if first_char <= 'j': location = 'Loomis 100' elif first_char <= o: location = 'DCL 1320' else: location = 'English 214'
34
If you were choosing between 6 possibilities, how many elif statements would you have: A) 1 B) 2 C) 3 D) 4 E) 5
35