Intro to
Computer
Science

Spring 2021
course
site
-->

March 29

... start recording

Any questions about anything?

Where we are :

I'll use the slides & my notes on decisions to talk through some of the new syntax and ideas.


Depending on time we may try at least one of these in-class coding projects.


I've also uploaded a variation on the guessing game that uses "try" to only accept valid inputs.

(However, as it is it also stops you from using control-C to quit. Better would be to only catch some exceptions, with except ValueError, since problems like int("one") produce a ValueError exception.)

Max of three numbers
--------------------
Write a program that asks for three numbers (a, b, c)
and then tells you which is the largest.
There's a discussion of several ways to do this at the end of chapter 7,
starting on slide 62 of Zelle's lecture slides.
We'll try it first, then discuss some of the different variations.
def max_of_three(a,b,c):
    """ return the largest of three values """
    # TODO : put the answer in a variable called maximum ...
    return maximum
def main():
    x = int(input("What is x? "))
    y = int(input("What is y? "))
    z = int(input("What is z? "))
    biggest = max_of_three(x, y, z)
    print(f"biggest is {biggest}")
main()

Here's one way to do it.


Guessing game
-------------
Write a program that picks a random number from 1 to 100,
then asks you to make guesses. After each guess, it tells you "too high",
"too low", or "you win in X guesses". 
I have a similar program in my notes on decisions.

Here's my version.


See you Thursday. ;)

https://cs.bennington.college /courses /spring2021 /introcs /notes /march29
last modified Mon March 29 2021 11:46 am

attachments [paper clip]

  last modified size
TXT guessing_game.py Mon Mar 29 2021 11:21 am 816B
TXT guessing_game_with_input_checking.py Mon Mar 29 2021 11:44 am 1.1K
TXT max3.py Mon Mar 29 2021 10:32 am 933B