day06notes

.py

School

Georgia Institute Of Technology *

*We aren’t endorsed by this school

Course

1301

Subject

Computer Science

Date

Dec 6, 2023

Type

py

Pages

4

Uploaded by BrigadierBravery5404

Report
""" Day 06 - More conditionals 1. Recap 2. More Boolean Practice a. Evaluating Boolean Expressions b. Using Boolean Expressions in Conditionals c. Returning a Boolean from a Function d. Using Functions in Conditionals 3. Advanced Conditionals a. Nested if statements 4. The "in" operator a. Using "in" with strings """ # >>> Day 06 Miniquiz - Problem solving # === Recap: Conditionals # booleans ''' val1 = 78 val2 = 89 comparison = val1 >= val2 print(comparison) ''' # if/elif/else ''' val4 = 100 val3 = 10 if val3 < 80: print("first branch of conditional!") elif val4 > 50: print("second branch of conditional!") else: print("Nothing was satisfied!") ''' # if/if vs if/elif ''' val4=45 val3=100 if val4 > 20: print("Hey!") elif val3 > 90: print("Hello!") val4=45 val3=100 if val4 > 20: print("Bye!") if val3 > 90: print("Buh-bye!") ''' # === Conditionals in functions # Example: Write a function that takes as input someone's # grades on this course and returns their letter grade. # HINT: You might need to go to the syllabus to find the
# weights for exams, homeworks, labs, participation and # the final. ''' def letterGrade(mid, hw, quiz, final, lab): total = 0.4 * mid + 0.25 * hw + 0.05 * quiz + 0.2 * final + 0.1* lab print(total) if total >=90: return "A" elif total >=80: return "B" elif total >=70: return "C" elif total >=60: return "D" else: return "F" student1= letterGrade (90, 100, 100, 80, 100) print(student1) ''' # === Functions that return booleans # Example: Write a function that checks whether a number is # divisible by 4. The function should return the result # as a bool. ''' def isDivBy4(num): remainder = num % 4 if remainder == 0: return True else: return False print(isDivBy4(16)) def oneLiner(num): return num%4 == 0 ''' # Example: Write a function that checks whether a password # is correct or not. The function should return the result # as a bool. ''' def isCorrectPwd(pwd): databasePwd = "helloKitty500" if pwd == databasePwd: return True else: return False ''' ''' print(isCorrectPwd("HelloKitty900")) ''' # === Logical operators (not, and, or) # not ''' var23 = True
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help