Unformatted text preview:

shared via CourseHero com This study resource was This study source was downloaded by 100000831992239 from CourseHero com on 11 05 2021 13 42 36 GMT 05 00 https www coursehero com file 57993440 L07docx from random import randintTAX 3 625OVER 1 5OVERH 40def hi lo game high Plays a random higher lower guessing game Use count hi lo game high Parameters high maximum random value int 1 Returns count the number of guesses the user made int count 1 number randint 1 high guess int input Guess while guess number if guess number print Too high try again if guess number print Too low try again count 1 guess int input Guess if guess number print Congratulations good guess return countdef power of two target Determines the nearest power of 2 to a given target Use power power of two target Parameters target value to find nearest power of 2 int 0 Returns power first power of 2 target int n 2 while n target shared via CourseHero com This study resource was This study source was downloaded by 100000831992239 from CourseHero com on 11 05 2021 13 42 36 GMT 05 00 https www coursehero com file 57993440 L07docx n n 2 return n def population growth target current rate Determines the number of years to reach a target population Use years population growth target current rate Parameters target target population int 0 current current population int 0 rate percent rate of growth float Returns years the number of years to reach target population int years 0 while current target current current current rate 100 years 1 return yearsdef sum squares target Determines the sum of squares closest to and greater than or equal to a target value Use final sum squares target Parameters target target value int 0 Returns final the final sum of squares target int n 0 count 1 while n target n n count 2 count 1 return ndef positive statistics shared via CourseHero com This study resource was This study source was downloaded by 100000831992239 from CourseHero com on 11 05 2021 13 42 36 GMT 05 00 https www coursehero com file 57993440 L07docx Asks a user to enter a series of positive numbers then calculates and returns the minimum maximum total and average of those numbers Stop processing values when the user enters a negative number The first number entered must be positive Use minimum maximum total average positive statistics Returns minimum smallest of the entered values float maximum largest of the entered values float total total of the entered values float average average of the entered values float count 1 num float input First positive value while num 0 num float input First positive value minimum num maximum num total num num2 float input Next positive value while num2 0 if num2 minimum minimum num2 if num2 minimum maximum num2 count 1 total total num2 num2 float input Next positive value average total count return minimum maximum total average def num categories Asks a user to enter a series of numbers then counts and returns how may positives negatives and zeroes there are Stop processing values when the user enters 999 Use negatives zeroes positives num categories Returns negatives number of negative values int zeroes number of zero values int positives number of positive values int shared via CourseHero com This study resource was This study source was downloaded by 100000831992239 from CourseHero com on 11 05 2021 13 42 36 GMT 05 00 https www coursehero com file 57993440 L07docx negatives 0 zeroes 0 positives 0 num int input First Value while num 999 if num 0 negatives 1 elif num 0 positives 1 else zeroes 1 num int input Next Value return negatives zeroes positives def meal costs Asks a user the costs of breakfast lunch and supper for each day the user was away Assumes there is at least one day and after entering data for each day asks the user whether they want to enter data for another day Calculates total costs for meals Use b total l total s total a total meal costs Returns b total total breakfasts cost float l total total lunches cost float s total total suppers cost float a total all meals cost float count 1 b total 0 l total 0 s total 0 t total 0 print Day format count b float input How much was breakfast l float input How much was lunch s float input How much was supper t b l s t total t b total b l total l s total s print Your total for the day was format t day str input Were you away another day Y N shared via CourseHero com This study resource was This study source was downloaded by 100000831992239 from CourseHero com on 11 05 2021 13 42 36 GMT 05 00 https www coursehero com file 57993440 L07docx while day Y count 1 print Day format count b float input How much was breakfast l float input How much was lunch s float input How much was supper t b l s t total t b total b l total l s total s print Your total for the day was format t day str input Were you away another day Y N return b total l total s total t total def budget available Asks a user for a series of expenses in a month Calculate the total expenses and determines whether the user is in Surplus Deficit or Balanced Use expenses balance status budget available Parameters target target value int 0 Returns expenses total monthly expenses float balance remaining balance float status One of str Surplus if user budget is in surplus Deficit if user budget is in deficit Balanced if user budget is balanced total 0 exp float input Enter an expense 0 to quit total exp while exp 0 exp float input Enter another expense 0 to quit total exp net available total status if net 0 status Deficit elif net 0 status Surplus shared via CourseHero com This study resource was This study source was downloaded by 100000831992239 from CourseHero com on 11 05 2021 13 42 36 GMT 05 00 https www coursehero com file 57993440 L07docx else status Balanced return total net status def get int low high Asks a user for an integer value between low and high and continues asking until an acceptable value is input Use value get int low high Parameters low the lowest acceptable integer inclusive int high the higest acceptable integer inclusive int low Returns value a number between low and high int value int input Enter a value between and format low high while value high or value low if value high print Value entered is too high if value low print Value entered is too low value int input Enter a value between and format low high return valuedef employee payroll Calculates and returns the weekly employee payroll for all employees in an organization For each employee ask the user for


View Full Document

WLU CP 104 - Lecture notes

Download Lecture notes
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 Lecture notes 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 Lecture notes 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?