#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Felix Muzny 9/16/2022 DS 2000 Lecture 3 - solidifying input/functions, reading/writing files, main() Logistics: - Homework 1 (due *today* @ 9pm) - because of the difficulties with Spyder installation/upgrade, there will be NO LATE PENALTY for HW 1 - Homework 2 (released, available on the course website, due next Friday) 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 - // operator --- Question: What does the // operator do? A. it is the same as the / operator B. it is the same as the % operator C. it takes the floor (always rounds down) of a division C. it takes the ceiling (always rounds up) of a division E. it only works with integers Warm-up 1 - variable assignment --- Question: What is the value of the variable num_cats at the end of the following code snippet? num_cats = 2 num_years = 3 num_cats = num_cats + num_years * 4 A. 14 B. 20 C. 11 D. something else E. Error Warm-up 2 - input() and type casting --- Question: What is the type of the variable fave_num when we call the type() function? fave_num = input("what is your favorite number? ") int(fave_num) print(type(fave_num)) A. int B. float C. str D. something else E. Error """ """ review: vocabulary ---- - function - argument/parameter - return/return value - data type """ """ additions: vocabulary ---- - "call" - "pass in" """ """ Computer organization: files, folders, home directories, oh my! --- Where does this file live? How do I know? With your neighbor: where is the file that you are currently editing located? Question: open a new file in Spyder. What is its name? A. untitledX.py B. temp.py C. something else What's that .spyder-py3 thing??? What's the temp file??? Prof. Felix's recommendations: ---- """ """ Structuring our programs --- So far... Now... """ """ Today's problem: 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. """ # see zoo.py """ Getting started with data ---- To read data from an external file, we need to make sure that we understand the file system on our computers. Importantly: - where does the python program that we're editing exist - where does the data file that we want to work with exist When working with files, we do three things: 1. open the file 2. do stuff with the contents of the file 3. close the file """ # opening a file example with animals.txt """ Reading from a file and the "cursor" ---- When python opens a file (successfully), file.readline() function --- 1. Does this function give me any information back? 2. what is this function's name? 3. what information does this function need to run? """ # reading multiple lines from a file """ Today's problem, updated: 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. Read and display the information about what animals exist in the zoo from the animals.txt file. """ """ Summary: """