Question

Lab 5 Instructions For Lab 5, you will be writing a more complex modular program that...

Lab 5 Instructions For Lab 5, you will be writing a more complex modular program that uses at least two arrays, and has at least one loop that accesses the data in the arrays. As long as your program satisfies the requirements listed below, you are free to design and write any type of program that you care to. You are encouraged to be creative, and pick something that has meaning for you, because you'll have more fun. Feel free to create a more complex version of the program you did in an earlier lab, as long as it meets all of the additional requirements below. Requirements Your lab submission should consist of a single Python file, Lab5.py, uploaded to the Lab 5 dropbox. The Lab5.py file should meet all of the following requirements: Your name given as the author. Comments including a brief description of the program, Input List and Output List, and full pseudocode. Place the pseudocode for each module above the module's Python code. The program must have at least one input and at least one output. All user input must be validated. This means the user is not allowed to just enter any value. You must check the value, and ask the user to enter it again, and repeat this loop until the user enters a valid value. Your program must use at least two arrays in meaningful ways. These two arrays can contain any type of values, as long as they are both used meaningfully in your program. Your program must have at least one loop that accesses the data in the arrays. For example, you might have an input loop that asks the user to enter the data one element at a time (be sure to validate the data). Or, you might have an output loop that writes the data to the console. Or, you might have a calculation loop that calculates one or more values, such as minimum value, maximum value, averages, and so on. You can have all three of those types of loops, if you want (the Lab 5 walkthrough video shows an example of each). Your program should be organized into separate modules. Each module should be "cohesive" and should only do one thing. Use parameters and arguments to pass values into your modules (don't use global variables). The Python code should run correctly, and the logic should match your pseudocode. Please Write in PyCharm.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Python Code:

Output Snapshot:

Text Code:

'''
__author__ : XXXXXX
__description__ : Python program to take the input two arrays/list
from the user and calculate minimum, maximum and average
of the array element
'''

'''
__function_name__ : userInputArray
__description__ : function/module to take the validated input from the
user and returning the list of provided size
__input__ : size (integer type)   
__output__ : array_list (list of integer type)
'''
def userInputArray(size):
# declaring the array_list with size
array_list = [None]*size
# Loop to input the array value
for i in range(len(array_list)):
while True:
# Propmting the user to input array element
input_value = input("Enter element " + str(i) + " :")
# Validation of the input and storing it in the array_list
try:
array_list[i] = int(input_value)   
break;
except ValueError:
print("Please enter integer value")
  
return array_list

'''
__function_name__ : calculateMinValue
__description__ : function/module to take the array_list as the input and
computing the minimum value and returning the min_val
__input__ : array_list (list of integer type)   
__output__ : min_val (integer type)
__pseudocode__ :

min_val = first element of array_list
for each value of array_list:
if min_val is greater than array_list value:
min_val = array_list value
'''
def calculateMinValue(array_list):
min_val = array_list[0]
for i in range(len(array_list)):
if min_val > array_list[i]:
min_val = array_list[i]
  
return min_val

'''
__function_name__ : calculateMaxValue
__description__ : function/module to take the array_list as the input and
computing the maximum value and returning the max_val
__input__ : array_list (list of integer type)   
__output__ : max_val (integer type)
__pseudocode__ :

max_val = first element of array_list
for each value of array_list:
if max_val is less than array_list value:
max_val = array_list value
'''   
def calculateMaxValue(array_list):
max_val = array_list[0]
for i in range(len(array_list)):
if max_val < array_list[i]:
max_val = array_list[i]
  
return max_val
  
'''
__function_name__ : calculateAvgValue
__description__ : function/module to take the array_list as the input and
computing the average value and returning the avg_val
__input__ : array_list (list of integer type)   
__output__ : avg_val (integer type)
__pseudocode__ :

avg_val = 0
sum_val = 0
for each value of array_list:
sum_val = sum_val + array_list value
  
avg_val = sum_val / length of array_list
'''   
def calculateAvgValue(array_list):
avg_val = 0
sum_val = 0
for i in range(len(array_list)):
sum_val = sum_val + array_list[i]
  
avg_val = sum_val/len(array_list)
return avg_val

'''
__function_name__ : main
__description__ : Entry Point of the code
__input__ : none
__output__ : none

'''   
def main():
# Variable to store the size of the arrays/list to be used
size_of_array = 5
# 2 arrays declaration with its size
array1 = [None]*size_of_array
array2 = [None]*size_of_array
  
# Taking user input for first array2
print("=========== INPUT 1 =============")
print("Enter array1 elements")
array1 = userInputArray(size_of_array)
print("=========== INPUT 1 =============")
print("Enter array2 elements")
array2 = userInputArray(size_of_array)
  
# Computing the minimum value
min_val_array1 = calculateMinValue(array1)
min_val_array2 = calculateMinValue(array2)
# Computing the maximum value
max_val_array1 = calculateMaxValue(array1)
max_val_array2 = calculateMaxValue(array2)
# Computing the average value
avg_val_array1 = calculateAvgValue(array1)
avg_val_array2 = calculateAvgValue(array2)
  
# Displaying the Output
print("=========== OUTPUT =============")
print("array1 Minimum value : " + str(min_val_array1))
print("array1 Maximum value : " + str(max_val_array1))
print("array1 Average value : " + str(avg_val_array1))
print("array2 Minimum value : " + str(min_val_array2))
print("array2 Maximum value : " + str(max_val_array2))
print("array2 Average value : " + str(avg_val_array2))

# Starting of the code
if __name__ == "__main__":
main()

Explanation:

  • The code is written and run in Python 3.
  • Please change XXXX to your name in the line number 11 of the code.
  • Please refer code comments for the understanding purpose.
Add a comment
Know the answer?
Add Answer to:
Lab 5 Instructions For Lab 5, you will be writing a more complex modular program that...
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
  • I am writing a Python program to serve as a fitness tracker. I would love some...

    I am writing a Python program to serve as a fitness tracker. I would love some input as to how you would code this. I've included what I want this program to accomplish, what I will keep track of, and below all of that I have posted the assignment guidelines. Any suggestions on how to make this better/ more efficient would be welcome! I'm thinking of making a weekly tracker that takes input per day, and outputs at the end...

  • This needs to be written in Python. I'm writing this but I'd love to see how...

    This needs to be written in Python. I'm writing this but I'd love to see how others would do it. I have idea to make a program to keep track of reading. Set goal per day. Input minutes per day & book read. Could accumulate for whole month. Input daily, but you can input it all at the end of the week if you want. I want the user to be prompted to enter a numerical value and book for...

  • In this lab you will convert lab5.py to use object oriented programming techniques. The createList and...

    In this lab you will convert lab5.py to use object oriented programming techniques. The createList and checkList functions in lab5.py become methods of the MagicList class, and the main function of lab6.py calls methods of the MagicList class to let the user play the guessing game.                              A. (4pts) Use IDLE to create a lab6.py. Change the 2 comment lines at the top of lab6.py file: First line: your full name Second line: a short description of what the program...

  • need help with python program The objectives of this lab assignment are as follows: . Input...

    need help with python program The objectives of this lab assignment are as follows: . Input data from user Perform several different calculations Implement conditional logic in loop • Implement logic in functions Output information to user Skills Required To properly complete this assignment, you will need to apply the following skills: . Read string input from the console and convert input to required numeric data-types Understand how to use the Python Modulo Operator Understand the if / elif /...

  • Write a modular program using visual c++ to simulate the Game of Life and investigate the...

    Write a modular program using visual c++ to simulate the Game of Life and investigate the patterns produced by various initial configurations. Some configurations die off rather rapidly; others repeat after a certain number of generations; others change shape and size and may move across the array; and still others may produce ‘gliders’ that detach themselves from the society and sail off into space! Since the game requires an array of cells that continually expands/shrinks, you would want to use...

  • Create a new Python program in IDLE, and save it as lab8.py.(Again, I recommend saving lab...

    Create a new Python program in IDLE, and save it as lab8.py.(Again, I recommend saving lab progranms Your Python program will do the following: Create an empty list . Use a for loop to ask the user for 10 numbers. Add each number to your list using the append metha . Use another for loop to print the list in reverse order, one per line . Use a while loop to count how many positive numbers are in the list...

  • [PYTHON] Create a chatbot program in Python: a program that appears to talk intelligently to a...

    [PYTHON] Create a chatbot program in Python: a program that appears to talk intelligently to a human using text. Your program should involve asking the user questions and having the computer respond in a reasonably intelligent fashion based on those answers. For example, here is a sample chat: ChatBot: Welcome, I am Chatbot . What is your name? User: My name is Abby . ChatBot: Hello Abby. How old are you? User: 22. <---- Input ChatBot: That is older than...

  • PYTHON PROGRAMMING Instructions: You are responsible for writing a program that allows a user to do...

    PYTHON PROGRAMMING Instructions: You are responsible for writing a program that allows a user to do one of five things at a time: 1. Add students to database. • There should be no duplicate students. If student already exists, do not add the data again; print a message informing student already exists in database. • Enter name, age, and address. 2. Search for students in the database by name. • User enters student name to search • Show student name,...

  • Write a program that asks the user to enter a password, and then checks it for...

    Write a program that asks the user to enter a password, and then checks it for a few different requirements before approving it as secure and repeating the final password to the user. The program must re-prompt the user until they provide a password that satisfies all of the conditions. It must also tell the user each of the conditions they failed, and how to fix it. If there is more than one thing wrong (e.g., no lowercase, and longer...

  • Note: You must write this program in Python. General Requirements The program should display a menu...

    Note: You must write this program in Python. General Requirements The program should display a menu and allow the user to perform one of the following tasks. Add an item to the list Delete an item from the list Print the list Print the list in reverse Quit the program The program should run until the user chooses to quit. In Python, programmatically quitting the application is achieved with the exit() procedure. You should use a List to store the...

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