Question

Python Programming language Write the following functions: getNumInRange(prompt, min, max) - get...

Python Programming language

Write the following functions:

  • getNumInRange(prompt, min, max) - gets a number from the user within the specified range, prompting with 'prompt'
  • calcAvg(values) - calculates and returns the average from a supplied list of numeric values
  • menu(somelist) - creates a numbered menu from a list of strings. Then, have the user select a valid choice (number), and return it. Use the getNumInRange() funtion to do this.
  • getAlbum() - prompts the user for information to populate a dictionary representing a music album, then returns the dictionary.
  • main() - demonstrate the usage of these functions in main()

    Python Programming Language Note: You can use for loop, while loop, if, elif, else statements. We have yet to learn files and object oriented programming, so do not use the oop and files. Thank You.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
I have done the code. Let me know if you have any doubt.

def getNumInRange(prompt, min, max):
    
    while True:
        num=int(input(prompt))
        if num>=min and num<=max:
            return num
        else:
            print('Number is not in range. Please try again')

def calcAvg(values):
    total=0
    count=0
    for item in values:
        total=total+item
        count=count+1
    return total/count
        
def main():
    prompt='Enter the number: '
    min=1
    max=5
    num=getNumInRange(prompt, min, max) 
    print(num)
    values=[1,2,3,4,5]
    avg=calcAvg(values)
    print(avg)
    
main()
Add a comment
Know the answer?
Add Answer to:
Python Programming language Write the following functions: getNumInRange(prompt, min, max) - get...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PYTHON PROGRAMMING NEED HELP ASAP You will write an application to manage music collections -- a music collection is a l...

    PYTHON PROGRAMMING NEED HELP ASAP You will write an application to manage music collections -- a music collection is a list of albums. The named tuples used for Albums and Songs are defined below, and an example of a music collection is given. (DO NOT HARDCODE THE VALUES FOR MUSIC!) Album = namedtuple('Album', 'id artist title year songs') Song = namedtuple('Song', 'track title length play_count') MUSIC = [ Album("1", "Peter Gabriel", "Up", 2002, [Song(1, "Darkness", 411, 5), Song(2, "Growing Up",...

  • Please use python 3 programming language Write a function that gets a string representing a file...

    Please use python 3 programming language Write a function that gets a string representing a file name and a list. The function writes the content of the list to the file. Each item in the list is written on one line. Name the function WriteList. If all goes well the function returns true, otherwise it returns false. Write another function, RandomRange that takes an integer then it returns a list of length n, where n is an integer passed as...

  • For Python 3.8! Copy and paste the following bolded code into IDLE: movies = [[1939, 'Gone...

    For Python 3.8! Copy and paste the following bolded code into IDLE: movies = [[1939, 'Gone with the Wind', 'drama'],           [1943, 'Casablanca', 'drama'],           [1965, 'The Sound of Music', 'musical'],           [1969, 'Midnight Cowboy', 'drama'],           [1972, 'The Godfather', 'drama'],           [1973, 'The Sting', 'comedy'],           [1977, 'Annie Hall', 'comedy'],           [1982, 'Ghandi', 'historical'],           [1986, 'Platoon', 'action'],           [1990, 'Dances with Wolves', 'western'],           [1992, 'Unforgiven', 'western'],           [1994, 'Forrest Gump', 'comedy'],           [1995, 'Braveheart', 'historical'],           [1997,...

  • Write a program IN PYTHON that checks the spelling of all words in a file. It...

    Write a program IN PYTHON that checks the spelling of all words in a file. It should read each word of a file and check whether it is contained in a word list. A word list available below, called words.txt. The program should print out all words that it cannot find in the word list. Requirements Your program should implement the follow functions: main() The main function should prompt the user for a path to the dictionary file and a...

  • In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one...

    In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one character string. Using a single dimension array, populate the array with the character string, call a function using pointers to reverse order the character string, pass back to the main the output and total_count_of_characters. (maybe use a global variable for the total count). Print display the reversed char string and total_count.

  • In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one...

    In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one character string. Using a single dimension array, populate the array with the character string, call a function using pointers to reverse order the character string, pass back to the main the output and total_count_of_characters. (maybe use a global variable for the total count). Print display the reversed char string and total_count.

  • PYTHON. Write the following functions without using any predefined functions unless specified. def min (dataList) :      ...

    PYTHON. Write the following functions without using any predefined functions unless specified. def min (dataList) :       #returns the smallest value of the data values in dataList def max (dataList):        #returns the largest value def getRange (dataList) def mean (dataList) :     #returns the average of data values def median (dataList):    #returns the middle value of an ordered list #note: to sort the list first, may use the predefined sort function Then write a test1 function to test the above functions using...

  • NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions...

    NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions Work with files Overview This lab will have you store the birthdays for a group of people. This program will store the information with the focus on the date of the month and not on the individual. The point of this program is to be able to see who has a birthday on a given day or to create a table of birthdays, in...

  • NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions...

    NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions Work with files Overview This lab will have you store the birthdays for a group of people. This program will store the information with the focus on the date of the month and not on the individual. The point of this program is to be able to see who has a birthday on a given day or to create a table of birthdays, in...

  • PROJECT 6    Functions You are to write a PYTHON program which: *Defines the following 4  functions: whoamI()...

    PROJECT 6    Functions You are to write a PYTHON program which: *Defines the following 4  functions: whoamI() This function prints out your name and lists any programming course you have taken prior to this course. isEven(number) This function accepts one parameter, a number, and prints out a message indicating if the number is even or odd. Keep in mind that a number is even if there is no remainder when the number is divided by two. printEven(number) This function accepts one...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT