Question

In: Computer Science

Python On occasion, programs are mis-written such that a loop has no way to exit. This...

Python

  1. On occasion, programs are mis-written such that a loop has no way to exit. This is known as an _______________________.

  2. 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.

Solutions

Expert Solution

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]))

Related Solutions

Why is an exit condition so important for a while loop?
Why is an exit condition so important for a while loop?a.An exit condition is not vital.  A while loop works fine without one.b.So the programmer knows when it is okay to leave the room.c.If no exit condition is provided, while loops cannot continue beyond one iterationd.It allows the loop to end instead of running indefinitely.e.While loops are unstable, and must know how to exi
Write a Python program that has a loop to continuously ask the user for a number,...
Write a Python program that has a loop to continuously ask the user for a number, terminating the loop when the number entered is -1. Inside the loop, 1.) display one asterisk(*) if the number is 1, 2.) two asterisk(**) if the number is 2 and 3.) "OTHER" if the number is any other number.
Write a python code which prints triangle of stars using a loop ( for loop )...
Write a python code which prints triangle of stars using a loop ( for loop ) Remember what 5 * "*" does The number of lines of output should be determined by the user. For example, if the user enters 3, your output should be: * ** *** If the user enters 6, the output should be: * ** *** **** ***** ****** You do NOT need to check for valid input in this program. You may assume the user...
The Objectives are to: Use IDLE IDE for Python. Develop a few simple Python programs and...
The Objectives are to: Use IDLE IDE for Python. Develop a few simple Python programs and show they will translate and run. Experience error messages when you enter bad syntax the interpreter cannot understand. Discussion: The best way to learn Python (or any programming language) is to write & run Python programs. In this lab you will enter two programs, and run them to produce the output. Then deliberately insert syntax errors to see what kinds of error messages you...
Loop invariants: Consider the following Python function that merges two sorted lists. Here is a loop...
Loop invariants: Consider the following Python function that merges two sorted lists. Here is a loop invariant for loop 1: “the contents ofnewlistare in sorted order,newlistcontainsaelements oflistAandbelements oflistB” def mergeSortedLists(listA, listB):  newlist = [ ]  a = 0  b = 0  # loop 1  while a < len(listA) and b < len(listB):   if listA[a] < listB[b]:    newlist.append(listA[a])    a +=1   else:    newlist.append(listB[b])    b +=1  if a < len(listA):   newlist.extend(listA[a:])  if b < len(listB):   newlist.extend(listB[b:])  return newlist (a) Write down (in regular...
in python please Q1) Create a Singly link list and write Python Programs for the following...
in python please Q1) Create a Singly link list and write Python Programs for the following tasks: a. Delete the first node/item from the beginning of the link list b. Insert a node/item at the end of the link list c. Delete a node/item from a specific position in the link list Q2) Create a Singly link list and write a Python Program for the following tasks: a. Search a specific item in the linked list and return true if...
David is driving his prius on the freeway and reaches his exit. The exit has a...
David is driving his prius on the freeway and reaches his exit. The exit has a radius of curvature of 25 m and is banked at 38 degrees. How fast can David travel around the curve on a dry day (where the coefficient of friction between his tires and the road is 1)? How fast can he travel around the curve on a rainy day (when the coefficient of friction between his tires and a wet road is 0.75)? Give...
Occupancy data from a single loop detector was obtained from a one way street. The loop...
Occupancy data from a single loop detector was obtained from a one way street. The loop detector has a length of 6 feet and was observed to have six vehicles cross over it in a period of 30 seconds. The duration and the length of each vehicle are shown in the table below. Use the average vehicle length in your calculations. Estimate the values of q, k and u (flow, density and speed) Vehicle 1 2 3 4 5 6...
Python Write a for loop with a range function and format output as currency Use an...
Python Write a for loop with a range function and format output as currency Use an input statement to ask the user for # of iterations using the prompt: #? [space after the ?] & assign to a variable Convert the variable to an integer Use a for loop and a range function to display all whole numbers from 1 to the user entered number Display the value of the item variable on screen in each iteration in the following...
2) create a python program that uses a for loop and range to print out the...
2) create a python program that uses a for loop and range to print out the values 10 8 6 4 2 3) Create a python program that yses a for loop to print out ["bob","al","bert"]
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT