#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Felix Muzny 9/23/2022 DS 2000 Lecture 5 - while loops, random module Logistics: - Homework 2 due *tonight* @ 9pm - late deadline: Sunday @ 9pm - Quiz 3 goes out: *MONDAY @ 9AM* - expect all future quizzes to go out on Mondays @ 9am - Homework 3 is available *now* - after lecture today, you'll have all the tools that you need to complete the homework! - Homework 1 grades were released this morning - you have one week to submit regrade requests via Gradescope - this will be the case for all homeworks in general! - 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 - string concatenation --- Say you have the following code: # assume the user types "my_fancy_file" file = input("what is the file name? ") extension = ".txt" print(file + "extension") A. my_fancy_file.txt B. file.txt C. my_fancy_fileextension D. fileextension E. Error Warm-up 2 - conditionals --- What is the output from the following code? bday = 23 if bday == 23: print("happy birthday day") else bday != 23: print("today is not your birthday day") A. happy birthday day B. happy birthday day then today is not your birthday day C. today is not your birthday day D. nothing E. Error """ """ Conditionals: what we rememember --- """ """ Advanced conditionals: if/elif/else --- """ """ Advanced conditionals: if-then-if --- """ """ General conditionals syntax: how many of what? --- """ """ Control structures ----- When we learned about conditionals, we learned about a *control structure*. This is python code that dictates what code should be executed next... """ """ random module --- """ """ Example problem: --- Write a program, hotcold.py, that randomly picks a number between 1 and 10 then has the user guess a number. If the user is correct, congratulate them. If the user is too high, tell them "too high!". If the user is too low, tell them "too low!" """ """ Repetition --- On Tuesday, we talked about how important it is for our programs to be able to do all of the following things: 1) Memory 2) Re-using code 3) Branching 4) Repetition """ """ While loops --- Conditionals, but if you gave them jet engines! """ # examples of while loops """ An unfortunate discovery --- What is infinity and what does it look like in python? """ # be very careful with the code below! """ Example problem (updated): --- Write a program, hotcold.py, that randomly picks a number between 1 and 10 then has the user guess a number. If the user is correct, congratulate them *and stop the program*. If the user is incorrect, prompt them to guess again. Each time the user guesses tell them "warmer" if they are getting closer to the secret number and "colder" if they are getting farther away. """ # if we have time """ While loops + plotting ---- We can *absolutely* combine plotting with while loops. For instance, let's plot the guesses that the user was making in our hotcold.py program. """