Write a program named program71.py as follows. Follow instructions carefully to
ID: 3852363 • Letter: W
Question
Write a program named program71.py as follows. Follow instructions carefully to avoid point deductions.
In the main function:
create a list named states1 that holds the two-letter abbreviations of the first 10 USA states, in alphabetical order.
use a loop to process the list and display the abbreviations all on the same line, separated by a single space. See sample output.
make a second list named states2 by slicing. This new list must hold the middle four state abbreviations from states1.
execute a function named list_func with states2 as its sole argument.
inside the list_func function:
delete the second element in the list
insert the abbreviation for Texas into the list at index 2
prompt the user for the abbreviation of another state of your choice, then append it to the list
reverse the list
return the list to main
back in main, use a loop to iterate over the returned list, printing all abbreviations on one line separated by a space.
Sample Output
Initial list of state abbreviations
AL AK AZ AR CA CO CT DE FL GA
Enter the state abbreviation for Kentucky KY
List returned by list_func
KY CT TX CO AR
Explanation / Answer
Answer for the given Question:
Please see the below python code for for print the expected output in the problem statement.
def main():
states1 = ["AL", "AK", "AR", "AZ", "CA", "CO", "CT", "DE", "FL", "GA"]
for words in states1:
print(words, end=" ")
states2 = states1[3:7]
states2 = list_func(states2)
# don't forget to print here
def list_func(states2):
states2.pop(1)
states2.insert(1, 'TX')
state_variable = input("Enter the abbreviation of another state of your choice: ")
states2.append(state_variable)
states2.reverse(states2)
returned_states = list_func(states2)
print(returned_states)
return states2
main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.