-1

Text file contents: Do your brakes squeal when you stop fairly short? The squealing is a high-pitched noise usually caused by vibration. Squealing can occur when the brake linings are worn and need replacement, the brake drum or disc needs to be machined, the front disc brake pads are loose or missing their anti-rattle clips, the hardware that attaches the brake calipers is worn, or inferior brake linings are in use.

Do your brakes make a grinding noise that you can feel in the pedal? If so, stop driving immediately and have your vehicle towed to a brake repair shop. Further driving could damage the brake discs or drums. Grinding brakes are caused by excessively worn brake linings; when the lining wears off, the metal part of the brake pad or brake shoe contacts the brake disc or drum and can quickly ruin the most expensive mechanical parts of the brake system.

Does your vehicle bounce up and down when you stop short? Your shock absorbers may need to be replaced.

If your steering wheel starts vibrating when you accelerate, or when your steering wheel vibrates even while you’re going straight at a steady speed…

There are many reasons why your steering wheel “fights” your grip. Sometimes as you drive through your freeway, you may run into bumps and potholes that will cause your wheel to turn sharply immediately. This is why it pays to keep your eyes forward and to keep a steady hand on your wheel. But if you’re moving on smooth pavement with no road humps or bumps in sight, and your steering wheel continues to fight your grip, then you may have:

Possible Cause: wheels that are already out of balance.

Possible Solution: Take your car to the local garage to have your wheels re-balanced and realigned.

Possible Cause: Your wheels may be prying loose due to loose bolts.

Possible Solution: If you’re on the freeway, head to the emergency bay to inspect your lugs. Look at your wheel lugs to determine if they need tightening.

Possible Cause: You may have damaged brake discs.

Possible Solution: This coming weekend, take the time to inspect your braking system and to replace your rotors if necessary.

Possible Cause: Worn treading on your wheels or your tires are starting to wear unevenly.

Possible Solution: Check your tires if you need to replace them if the treading is all but gone. Also keep in mind that uneven wear and tear on your tires is a symptom of a bigger problem. Check your wheel alignment and balance to determine if it’s time to take your car to the shop.

I know this question has been answered before but the solutions do not work for me. In this case at the end of my program I ask the user 'is that all' and when the user inputs 'no' I want the program to start again so the user can go through the program again however I am not sure how to do this and I'm sorry because I know the question has been answered before but the solution just don't work on my program

import itertools
import time
import sys
brakes=["brakes","not","working","pedal"]
steering=["steering","wheel","stuck","won't","turn"]
invalid=True
while invalid==True:
    brakes_counter=0
    steering_counter=0
    wrong=input("What is wrong with your car").lower()
    problem = wrong.split()
    for i in problem:
                    if i in brakes:
                            brakes_counter +=1
                            invalid=False
                    elif i in steering:
                            steering_counter +=1
                            invalid=False
                    else:
                            print("try again")
                            break
with open('brakesandsteering.txt',"r") as text_file:
    if brakes_counter>steering_counter:
                            for line in itertools.islice(text_file,0,22):
                                    print(line)

    elif steering2>brakes2:
                            for line in itertools.islice(text_file,24,46):
                                    print(line)
    isthatall = input("is that all?yes/no").lower()
    if isthatall== "yes":
                        print("\nThank you for using my program")
                        sys.exit()
    elif isthatall == "no":
                        #i want it to go to the start again here
        while isthatall != "no" and isthatall !="yes":
                        time.sleep(1)
                        print("try again")
                        time.sleep(1)
                        isthatall=input("is that all?yes/no").lower()
  • Have you tried putting the code you want to run inside a function and putting the user interface code outside the function? –  Nov 13 '15 at 19:12
  • I'm sorry David I am new to python so I am not entirely sure what that means could you please explain it in a simpler way – fishguy101 Nov 13 '15 at 20:47
  • What is the contents of 'brakesandsteering.txt'? We can't run your code without it. Also, your indenting does not seem right. –  Nov 13 '15 at 21:33
  • Do your brakes squeal when you stop fairly short? The squealing is a high-pitched noise usually caused by vibration. Squealing can occur when the brake linings are worn and need replacement, the brake drum or disc needs to be machined, the front disc brake pads are loose or missing their anti-rattle clips, the hardware that attaches the brake calipers is worn, or inferior brake linings are in use. . – fishguy101 Nov 13 '15 at 21:52
  • If your steering wheel starts vibrating when you accelerate, or when your steering wheel vibrates even while you’re going straight at a steady speed… If you’re moving on smooth pavement with no road humps or bumps in sight, and your steering wheel continues to fight your grip, then you may have: Possible Cause: wheels that are already out of balance. Possible Solution: Take your car to the local garage to have your wheels re-balanced and realigned. – fishguy101 Nov 13 '15 at 21:54
  • I am really sorry but I just don't understand how to do it. If possible could you please copy and paste the sections of my code necessary and edit the code. Thank you David. – fishguy101 Nov 13 '15 at 21:55
  • Could you put the file contents in the question? –  Nov 13 '15 at 21:56
  • See the "share", "edit", and "flag" links? Use the "edit" link to edit your question. –  Nov 14 '15 at 00:06

1 Answers1

0

This is often called a "game loop". Wrap all of the logic of your program in a loop which checks this terminating condition. I'm not familiar with the language you're using, but in pseudo-code it would look like this:

continueApp = True
while continueApp == True
  #perform your application logic here

  continueApp = input("Is that all? (Y/N) ") == "N"

That's about it. Every time the program loops, the last thing it does is ask the user if they want to continue. If they do then the value is True and the loop iterates again. If they don't then the value is False and the loop terminates.

David
  • 208,112
  • 36
  • 198
  • 279
  • Thank you for your comment. Although unfortunately if I put True it doesn't loop the program again as when I inputted no to carry on the program the program just stopped. Please help. – fishguy101 Nov 13 '15 at 19:32
  • @fishguy101: When you debug this, where/how *specifically* does it deviate from what you expect? Is the value that governs the loop being changed? Is the input setting that value? Don't treat your code like a black box, debug it. – David Nov 13 '15 at 19:33
  • Sorry David. What I expect is that when I input 'no' at the end of the program it repeats the program again so the user can input another problem and get another solution. However when I put invalid==True ,like you said previously, it does not loop back to the start of the program, meaning the user cant go through the program again as when I input 'no' it just stops the program at that current point like a sys.exit(). I am sorry if I am not going into enough detail as I am new to python. – fishguy101 Nov 13 '15 at 19:48
  • I have even tried numerous other solutions on other questions but it does not loop to the start of the program – fishguy101 Nov 13 '15 at 19:49
  • @fishguy101: Well, if "no" should continue the loop then you'd want to invert the logic I presented in this answer. (I just updated the answer accordingly. Having a "negative condition" is sometimes considered unintuitive and I missed it.) Either way the concept is the same. Whatever answer *continues* the loop should result in the condition being `True`, and any other answer should result in it being `False`. I'm not sure how else to explain it. – David Nov 13 '15 at 19:52
  • Thank you David. I am really sorry but I just don't understand how to do it. If possible could you please copy and paste the sections of my code necessary and edit the code. Thank you again David. – fishguy101 Nov 13 '15 at 20:01