Efficient code?


#1

I am doing a project at school and I don't know how to make the code more efficient,

import time #This will slow parts down if commanded
while True:
print("Hello this is a phone troubleshooting quiz. ")
question1=input("What is the brand of your device?. ") #A main question
if question1=="iPhone": #A main answer
print("That is step 1 done, now we shall get onto step 2. ") #Notifies that it will move onto the next question
if question1=="HTC":
print("That is step 1 done, now we shall get onto step 2. ")
if question1=="Samsung":
print("That is step 1 done, now we shall get onto step 2. ")
if question1=="Nokia":
print("That is step 1 done, now we shall get onto step 2. ")

question2=input("What is wrong with your phone?. ") #A main question
if question2=="There's no dial tone": #A main answer
    print("That is step 2 done, now we shall get onto the final step?. ") #Notifies that it will move onto the next question
if question2=="I have a broken screen":
    print("That is step 2 done, now we shall get onto the final step?. ")
if question2=="I can't make calls":
    print("That is step 2 done, now we shall get onto the final step?. ")
if question2=="I can't receive calls":
    print("That is step 2 done, now we shall get onto the final step?. ")
if question2=="Water damage":
    print("That is step 2 done, now we shall get onto the final step?. ")
if question2=="It won't start up":
    print("That is step 2 done, now we shall get onto the final step?. ")

question3=input("We have finished, would you like to know the answer?. ")
if question3=="yes": #A yes or no question
    time.sleep(0.5)
    print("Problem: Okay your phone has/has a "+ question2) #Uses an answer which you have typed in
    time.sleep(0.5)
    print("Solution: You will need to go to your local repair shop") #A solution
    time.sleep(0.5)
    print("Solution: You could also go to your local phone provider to get a new one.")
if question3=="no": #Exits the program
    exit()

answer = input("Would you like to start again?. ").lower().strip() #A loop
if answer == "no":
    exit()

Thanks, Tom :slight_smile:


#2

Is it inefficient in some way? If so, then how?
What's it doing that it shouldn't? That would say a lot about what to change, right?
If you're talking about speed, then 99% of this program's execution time will be spent waiting on a human.

You're repeating yourself a whole lot. Can you motivate why that is necessary? Would a human think in those terms, or would a human do something more efficient? If so, what does the human do, and can't you describe that something in code?