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...

  • 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 /...

  • 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...

  • Python 3 coding with AWS/Ide. Objective: The purpose of this lab is for you to become familiar with Python’s built-in te...

    Python 3 coding with AWS/Ide. Objective: The purpose of this lab is for you to become familiar with Python’s built-in text container -- class str-- and lists containing multiple strings. One of the advantages of the str class is that, to the programmer, strings in your code may be treated in a manner that is similar to how numbers are treated. Just like ints, floats, a string object (i.e., variable) may be initialized with a literal value or the contents...

  • USING PYTHON PLEASE Write a program that calculates the factorial value of a number entered by...

    USING PYTHON PLEASE Write a program that calculates the factorial value of a number entered by the user. Remember that x! =x* (x-1)* (x-2)*... *3+ 2* 1. Your program should check the value input by the user to ensure it is valid (i.e., that it is a number > =1). To do this, consider looking at the is digit() function available in Python. If the user enters an incorrect input, your program should continue to ask them to enter a...

  • Question 3.1 Draw the class diagram for the ATM program in Question 2.1. Please find attached...

    Question 3.1 Draw the class diagram for the ATM program in Question 2.1. Please find attached the scenario in the photos. this is for programming logic and design Scenario A local bank intends to install a new automated teller machine (ATM) to allow users (i.e., bank customers) to perform basic financial transactions (see below figure). Each user can have only one account at the bank. ATM users should be able to do the following; View their account balance. Withdraw cash...

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
ADVERTISEMENT