Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can u aid with these 4 questions. Please use while loops and also separate the function and the main file. As well use the .format

Can u aid with these 4 questions. Please use while loops and also separate the function and the main file. As well use the .format python standard. Thank you in advance for the help.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
1. Implement the following function in the PyDev module functions. py and test it from a PyDev module named to1. py: def 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) Use the following lines to generate a random number between 0 and some high integer value: from random import randint def hi_lo_game(high) : . . . number = randint(1, high) . . . Sample testing: Guess: 50 Too high, try again. Guess: 35 Too low, try again. Guess : 40 Too low, try again. Guess: 45 Congratulations - good guess! You made 4 guesses. Test functions . py: Choose File No file chosen Submit2. Implement the following function in the PyDev module functions . py and test it from a PyDev module named to2. py: def power_of_two(target) : Determines the nearest power of 2 greater than or equal 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) Sample testing: Enter target number: 0 The closest power of 2 >= 0 is 1. Enter target number: 1 The closest power of 2 >= 1 is 1. Enter target number: 2 The closest power of 2 >= 2 is 2. Enter target number: 248 The closest power of 2 >= 248 is 256. Test functions . py: Choose File No file chosen Submit. Implement the following function in the PyDeV module functions.py and test it from a PyDev module named ta3.py: def population_growth(target, currentJ rate): Determines the number of years to reach a target population. Use: years = population_growth(target, current, rate) Parameters: target - target population (int > current) current - current population (int ) 1) rate - percent rate of growth (float > 8) Returns: years - the number of years to reach target population (int) Sample testing: i Target population: 1888 5 Current population: 1888 5 Growth rate (%): ;8 Years to reach target: 8 Target population: 18888 Current population: 1888 Growth rate (%): ;8 Years to reach target: 25 Target population: 18888 Current population: 1888 5 Growth rate (%): i i Years to reach target: 4 Test functions . py: Choose File No le chosen I Submit I 4. Implement the following function in the PyDev module functions . py and test it from a PyDev module named to4. py: def 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 : Returns : target - target value (int >= 0) final - the final sum of squares >= target (int) The sum of squares is the total of the squares of a series of integers. Thus the sum of squares of 3 is: 12 + 22 + 32 : 14 Sample testing: Sum of squares >= target 0 : 1 Sum of squares >= target 9 : 14 Sum of squares >= target 26 : 30 Sum of squares >= target 100 : 140 Test functions . py: Choose File No file chosen Submit

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions