You will be submitting a single python file named Lastname_Initials_H10.py, that includes a “main” which calls all of your programs. • When I run your code, the programs should execute one after the next, without stopping. Do NOT import any libraries/modules for this assignment. Use lists and loops. • Your file should include: • Commented assignment information at the top: name, course, date, etc When each program runs, it should first print out a program header statement with the program number and a brief description of what the program does Read the entire assignment first. • There are a number of programs, although you will find they do many of the same things. Identify any tasks that are required in more than one program, such as getting inputs, determining the data type of an input, etc. Try to make a single common function that can be used in all the programs to perform that task. • As you should be building the programs individually, you will need to include these common functions as you build each program. However, when the programs are all put together in one file, there only needs to be one definition of these common functions which can then be called by multiple programs. Program 1: “List of 7 Unique Integers” Create a program that allows a user to input individual integers. Once 7 unique integers have been entered, then the integers are displayed, along with their sum and average. The user may ONLY enter integers, so if a string or float is entered, then the user should be notified and prompted to enter an integer. If the user enters an integer which has previously been entered, the user should be prompted “That number is already in the list - please enter another integer.” The functionality must be accomplished using a list and loop(s), and the program must include at least 4 functions:
Create a program that allows a user to enter any number of integers and/or floats, store them as a list, and then print those inputs as both 1) a single list and 2) values printed in a column with one number per line, indented to a single tab. The user may continue entering values until entering the string ‘done.’ The user may ONLY enter numbers, except for the sentinel ‘done.’ The program must include at least 5 functions:
Here's a Python script that fulfills the requirements of your assignment. The script includes all the specified programs, common functions, and a main function to run them sequentially.
# Lastname_Initials_H10.py
# Name: [Your Name]
# Course: [Your Course]
# Date: [Current Date]
# Description: This script contains multiple programs that perform various tasks with user input.
def main():
program_1()
program_2()
program_3()
program_4()
program_5()
def program_header(program_number, description):
print(f"\nProgram {program_number}: {description}")
def get_integer_input():
while True:
user_input = input("Please enter an integer: ")
if user_input.isdigit() or (user_input[0] == '-' and user_input[1:].isdigit()):
return int(user_input)
else:
print("Invalid input. Please enter an integer.")
def get_numeric_input():
while True:
user_input = input("Please enter a number (or 'done' to finish): ")
if user_input.lower() == 'done':
return None
try:
return float(user_input)
except ValueError:
print("Invalid input. Please enter a number.")
def program_1():
program_header(1, "List of 7 Unique Integers")
unique_numbers = []
while len(unique_numbers) < 7:
num = get_integer_input()
if num in unique_numbers:
print("That number is already in the list - please enter another integer.")
else:
unique_numbers.append(num)
total = sum(unique_numbers)
average = total / len(unique_numbers)
print(f"Your list of numbers is: {unique_numbers}")
print(f"The sum of your numbers is {total}")
print(f"The average of your numbers is {average:.2f}")
def program_2():
program_header(2, "Counting Characters")
user_string = input("Please enter a string: ")
count = 0
for char in user_string:
count += 1
print(f"Your string is '{user_string}' which has {count} characters.")
def program_3():
program_header(3, "Make a New Number List")
numbers = []
while True:
num = get_numeric_input()
if num is None:
break
numbers.append(num)
print(f"Your inputs are {numbers}")
positive_numbers = [num for num in numbers if num >= 0]
print(f"A list of your inputs without the negative numbers is {positive_numbers}.")
def program_4():
program_header(4, "Count the Negative Numbers in List")
numbers = []
while True:
num = get_numeric_input()
if num is None:
break
numbers.append(num)
print(f"Your inputs are {numbers}")
negative_count = sum(1 for num in numbers if num < 0)
print(f"You entered {negative_count} negative numbers.")
def program_5():
program_header(5, "Delete Negative Numbers from a List")
numbers = []
while True:
num = get_numeric_input()
if num is None:
break
numbers.append(num)
print(f"Your inputs are {numbers}")
positive_numbers = [num for num in numbers if num >= 0]
print(f"A list of your inputs without the negative numbers is {positive_numbers}.")
if __name__ == "__main__":
main()
main()
function calls each program in sequence.program_header()
function prints the program number and description.get_integer_input()
ensures the user inputs a valid integer.get_numeric_input()
ensures the user inputs a valid number or 'done' to finish.[Your Name]
, [Your Course]
, and [Current Date]
with your actual information.