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. 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:
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 meets the requirements outlined in your assignment. The script includes three programs: one for collecting and displaying numbers, and another for counting negative numbers. It also includes common functions to handle user input and list operations.
# Lastname_Initials_H10.py
# Name: Your Name
# Course: Your Course
# Date: Today's Date
def main():
program_one()
program_two()
def program_one():
print("Program 1: Collect and Display Numbers")
numbers = get_numbers()
print_numbers(numbers)
print("Finished Program 1.")
def program_two():
print("Program 2: Count the Negative Numbers in List")
numbers = get_numbers()
negative_count = count_negatives(numbers)
print(f"Your inputs are {numbers}")
print(f"You entered {negative_count} negative numbers.")
print("Finished Program 2.")
def get_numbers():
numbers = []
while True:
user_input = input("Enter a number (or 'done' to finish): ")
if user_input.lower() == 'done':
break
try:
number = float(user_input) # Try to convert to float
numbers.append(number)
except ValueError:
print("Invalid input. Please enter a number.")
return numbers
def print_numbers(numbers):
print(f"Your numbers in a list are {numbers}")
print("The numbers you entered are:")
for number in numbers:
print(f"\t{number}")
def count_negatives(numbers):
count = 0
for number in numbers:
if number < 0:
count += 1
return count
if __name__ == "__main__":
main()
main()
function orchestrates the execution of the two programs.get_numbers()
: Handles user input, ensuring that only valid numbers are accepted. It returns a list of numbers.print_numbers(numbers)
: Takes a list of numbers and prints them in the specified formats.count_negatives(numbers)
: Counts and returns the number of negative numbers in the provided list.Lastname_Initials_H10.py
and execute it in a Python environment. The user will be prompted to enter numbers, and the program will handle the input and output as specified.