Skip to content

cs-fullstack-2019-spring/python-review-functions-cw1-marcus110379

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 

Repository files navigation

Python Review: Functions Classwork

Problem 1:

We will keep having this problem until EVERYONE gets it right without help (with variations :-P )
  • Create a function that has a loop
  • Prompt for numbers until the user enters q to quit
  • If the user doesn't enter q, ask them to input another number
  • When the user enters q to quit, print the SUM of all numbers entered

BONUS:

  • Write your code so that it it doesn't matter if the User enters a lowercase or an uppercase q to quit
  • Add extra validation to check that if the User doesn't enter q what they did enter is actually a number

Problem 2:

  • Create a function problem2()

  • In this function prompt the user for 2 numbers

  • Create a second function called do_the_math that accepts 2 parameters (the 2 entered numbers)

  • In the do_the_math calculate the SUM, DIFFERENCE, PRODUCT, and QUOTIENT (division result) and return them as a dictionary to the calling function

    Example: Dictionary result returned if the argumants 25 and 10 are passed to the function:

    {'diff': 15, 'prod': 250, 'quot': 2.5, 'sum': 35}

  • In your problem2() function, print the dictionary result returned from your do_the_math function using string literal formatting

    Example: Execution and Output

    Enter the First Number in the calculation:
    25
    Enter the Second Number in the calculation:
    10
    Here are your results for the numbers 25 and 10:
    The SUM result is 35
    The DIFFERENCE result is 15
    The PRODUCT result is 250
    The DIVISION result is 2.5
    
    

Help on Dictionaries: https://www.tutorialspoint.com/python/python_dictionary.htm

About

python-review-functions-cw1-marcus110379 created by GitHub Classroom

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published