NYU CSCI-UA 0002 - Exercises Using- Variables and Functions

Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Slide 5Intro to: Computers & Programming Defining Identifiers: Objects with Names V22.0002-001Adam MeyersNew York University Introduction to: Computers & Programming Exercises Using: Variables and FunctionsIntro to: Computers & Programming Defining Identifiers: Objects with Names V22.0002-001Exercise 1: Calculate an Average of 5 Numbers•Use the function input– input(prompt)• displays prompt• waits for user to type something• returns whatever the user types• The program should allow the user to input 5 items• At the end it should display the averageIntro to: Computers & Programming Defining Identifiers: Objects with Names V22.0002-001Problem 2: Calculate Birthday Biorhythms• Go to http://en.wikipedia.org/wiki/Biorhythm• Implement a function that given an age in number of days, would calculate and print one's biorhythms, i.e.,–def print_biorhythms(number_of_days): ...• Write a function that calls print_biorhtyhms. It queries the user for their age and then gives them the biorythm for their next birthday (assuming no leap years).Intro to: Computers & Programming Defining Identifiers: Objects with Names V22.0002-001Problem 3: Write a Mad Libs Program•Mad Libs– A game in which a passage of text is assumed with various blanks that are typed by parts of speech: adverb, adjective, noun, verb, etc.•We can create a program that plays this game interactively, prompting users to fill in these blanks•Use the function input againIntro to: Computers & Programming Defining Identifiers: Objects with Names V22.0002-001Mad Libs: Slide 2•Choose a short self-contained text from the web, e.g., the first paragraph of Wikipedia's featured article of the day.•Divide it into lines, with one print statement per line.•Replace some of the words with variables indicating their part of speech.•Precede print statements with queries to the user to set each of the variables.•Encapsulate the above into an executable


View Full Document

NYU CSCI-UA 0002 - Exercises Using- Variables and Functions

Download Exercises Using- Variables and Functions
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Exercises Using- Variables and Functions and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Exercises Using- Variables and Functions 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?