Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def part1(): print(' Part 1 - use a loop to add up the United States population') # Use a loop to add up all of

def part1(): print(' Part 1 - use a loop to add up the United States population') # Use a loop to add up all of the individual state populations # in the list state_populations. # Print the total, somthing like: # 'The population of the United States is x people'

# Some important instructions: # You may not use the sum() function. part1 is about practicing using # a loop to do the work. # Hint: consider making a variable to hold the total, assign to 0 prior to using it. # Hint: consider a for loop along with the "in" membership operator. # Hint: this be accomplished in just a few lines of code (less than 8, easily # put your cursor at the end of this line and press Enter

# end of your part 1 code def part2(): print(' Part 2 - how many populations are less than 5 million') # Using a loop, scan the entire state_populations list and find out how many # populations are less than 5 million. # Print something like: # 'x state populations are less than 5 million people' # Hint: again, consider making a variable to hold your count,assign to 0 prior to using it. def part3(): print(' Part 3 - Ask the user how many states to display') # Ask the user for a number between 0 and 50. Using a loop, start at the beginning # of the lists, and print out the state's name and corresponding population, one # entry per line until finished. # Example: # Display states: Enter 0-50: 3 # Georgia 10,617,423 # Ohio 11,689,100 # Arkansas 3,017,825 # print(f'{name:10,}') # insert your code next...

def part4(): print(' Part 4 - use a loop to print all the states containing a user supplied letter') # Create a loop that asks the user to provide an alphabetic letter. Each time a letter # is supplied, you will list out all the states names that contain that letter. # The user can exit the loop by supplying a non-letter to exit the loop. # Use something like # user_input = input('Find all the states with letter (any non-letter will stop):') # Treat lower case and upper case as different letters # If a valid letter is supplied, then gather into a list all the state names # containing that letter. Print the list. # If the list is empty, print something like "There were no states with that letter" # and ask again. # Hint: an easy way to do the input is making a string of acceptable letters, something like # all_the_letters = 'abcdef...zABC...Z' (I did not type it all out) # then test if user_input is a member of that letter string. # Stay in your loop and continue to ask for user input until they supply a non-letter. # # FOR THE HOMEWORK SCREENSHOT: See Canvas Programming Assignment for which letters # # insert your code next...

# end of your part 4 code

image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Finance questions

Question

How can you open other peoples minds?

Answered: 1 week ago

Question

What is the main characteristic of schizophrenia?

Answered: 1 week ago

Question

600 lb 20 0.5 ft 30 30 5 ft

Answered: 1 week ago