#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Felix Muzny 9/20/2022 DS 2000 Lecture 4 - boolean, conditionals, intro to data viz Logistics: - Quiz 2 goes out today @ 4:30pm, due Fri @ 9:50am - Homework 2 due Fri @ 9pm - we updated the write-up yesterday evening to include some more hints about problem 1 - think about applying to be a HASTAC scholar if you want to explore digital humanities more (https://www.hastac.org/initiatives/hastac-scholars) - remote attendance (https://bit.ly/remote-ds2000-muzny) Three ways to participate (please do one of these!) 1) via the PollEverywhere website: https://pollev.com/muzny 2) via text: text "muzny" to the number 22333 to join the session 3) via Poll Everywhere app (available for iOS or Android) Warm-up 0 - HW 2 status --- Where are you on HW 2 currently? A. haven't looked at it B. looked at the write up C. started coding D. finished a few problems E. finished Warm-up 1 - opening files to read from in python --- What is the first step to opening a file to read from in python? A. put the file and the python program in the same folder B. open the file C. call the file.readline() function D. close the file E. something else Warm-up 2 - opening files to read from in python --- What is the output of the following code, assuming that the file was opened successfully? animal_file = open("animals.txt", "r") animal_file.readline() print(animal_file.readline()) animal_file.close() A. prints the first line of the file B. prints the second line of the file C. prints the first and the second lines of the file D. prints no lines of the file E. Error """ """ review: program structure --- - main() """ """ review: built-in functions we know so far --- + max(), min() """ """ Making decisions ----- There are some key super powers that we need to write programs with lots of abilities. 1) Memory 2) Re-using code 3) Branching 4) Repetition """ """ Boolean data type --- A new data type! Like string, int, float, except this data type is extra special! Values: Casting function: """ # examples of variables w/ boolean values """ Boolean expressions --- Much like we can have arithmetic expressions (3 + 7 ** 2) evaluates to a numerical answer, we can have boolean expressions. Expressions that evaluate to a boolean answer. comparison operators: """ # examples of boolean expressions # What is the value of the following... """ Logical operators --- Comparison operators combine two values of type: _______ Logical operators combine two values of type: _______ """ # examples of logical operators """ Conditionals 1 --- Conditionals Syntax: if boolean expression: # code to run if the boolean expression is True """ # examples """ Conditionals 2 --- Syntax: if boolean expression: # code to run if the boolean expression is True else: # code to """ # examples """ Updating zoo.py ---- From last lecture: Write a program, zoo.py, that represents a zoo that we're starting. First, this program should greet the user (by name, of course), then tell them what animals we have in our zoo. Update: Now, we'll ask the user whether they are interested in visiting the reptile house or the aviary, then tell them the animals in the appropriate place based on their answers. (We'll have two data files—aviary.txt and reptile.txt) """ """ Introduction to data viz --- We'll use the library matplotlib.pyplot to create graphs in this class Basics: 1) import the matplotlib library 2) use plt.plot(x coordinate, y coordinate) to plot a point 3) when you're all done, call plt.show() """ """ Example problem: --- Write a program, distance.py, that reads the data from the two files days.txt and distances.txt and graphs them accordingly on a scatter plot. """ """ Example problem, updated: --- Write a program, distance.py, that reads the data from the *three* files: days.txt, distances.txt, and modes.txt graphs them accordingly on a scatter plot. Color days that were a run with one color and days that were a bike ride a different color. """ # if we have time """ random module ---- """