In: Computer Science
Python
On occasion, programs are mis-written such that a loop has no way to exit. This is known as an _______________________.
et_courses = [‘et710’, ‘et712’, ‘et710’, ‘et710’, ‘et574’,
‘et575’, ‘et710’, ‘et574’]
Write a python program (include a while loop) to remove the
multiple occurrences of ‘et710’ from the list above. Print the
beginning list as well as the modified list to demonstrate that it
worked.
--OUTPUT--
Before:
[‘et710’, ‘et712’, ‘et710’, ‘et710’, ‘et574’, ‘et575’, ‘et710’,
‘et574’]
After:
[ ‘et712’, ‘et574’, ‘et575’, ‘et574’]
----------------
3. Write Python program which asks the user to name a favorite movie.
Print a message for each movie the user enters.
Allow the user to enter ‘quit’ in order to exit.
Reference:
https://github.com/ehmatthes/pcc/blob/master/chapter_07/cities.py
---OUTPUT---
Please tell me one of your favorite movies: (Enter 'quit' when you
are finished.) Jaws Jaws was one of my favorite movies too!
Please tell me one of your favorite movies: (Enter 'quit' when you are finished.) 1917 1917 was one of my favorite movies too!
Please tell me one of your favorite movies:
(Enter 'quit' when you are finished.) No Country for Old Men No
Country for Old Men was one of my favorite movies too!
Please tell me one of your favorite movies: (Enter 'quit' when you are finished.) quit
----------------------------------
4. Write a python program which polls the user to provide the
names of subjects they have studied which required a lot of study
time. For each, ask them where they studied this subject.
When the user quits the program, print their responses as shown in
the example output below. Reference:
https://github.com/ehmatthes/pcc/blob/master/chapter_07/mountain_poll.py
Tell me about a subject you studied which required a lot of
study time? piano
Where did you study it? Julliard
Would you like to tell us about another subject which required a
lot of study time? (yes/ no) yes Tell me about a subject you
studied which required a lot of study time? Chemistry
Where did you study it? High School
Would you like to tell us about another subject which required a
lot of study time? (yes/ no) y Tell me about a subject you studied
which required a lot of study time? Python
Where did you study it? QCC
Would you like to tell us about another subject which required a lot of study time? (yes/ no) no
---OUTPUT---
--- Poll Results ---
In Julliard you studied piano.
In High School you studied Chemistry. In QCC you studied
Python.
Ans 1: Infinite loop
Python code for remaining problems below:
et_courses = ['et710', 'et712', 'et710', 'et710', 'et574', 'et575', 'et710', 'et574']
print (et_courses)
item_to_remove = et_courses [0];
while item_to_remove in et_courses:
et_courses.remove (item_to_remove)
print (et_courses)
#---------------------------------------------
movie = ""
while (movie != "quit"):
movie = input ("Please tell me one of your favorite movies: (Enter 'quit' when you are finished: ")
if movie != "quit":
print (movie + " was one of my favorite movies too!")
#-----------------------------------------------
subjects = []
schools = []
contnue = "yes"
while contnue == "yes":
subjects.append (input ("Tell me about a subject you studied which required a lot of study time? ") )
schools.append (input ("Where did you study it? "))
contnue = input ("Would you like to tell us about another subject which required a lot of study time? (yes/ no)")
print ("POLL RESULTS")
for i in range (len(subjects)):
print ("In {} you studied {}".format (schools[i], subjects[i]))