How can I shorten these questions / code


#1

I have no clue what I've done but is there anyway to shorten my questions and answer them easier.

print ("Welcome to the automated troubleshooting service for mobile phones")
print ("First we'll start by asking you some common problems")
x=input ('What type of mobile device do you own? ')
z=input ('Have you dropped your mobile device?(Yes/No)')
y=input ('Have you tried charging it?(Yes/No)')
w=input ('Is your screen working?(Yes/No)')

if (x=="iPhone" and z=="Yes" and y=="No" and w=="No"):
print ("Try charging your phone to start off with and if that doesn't work contact a professional.")
elif (x=="iPhone" and z=="Yes" and y=="Yes" and w=="No"):
print ("Contact a iPhone engineer to see if you've damaged your mobile device.")
elif (x=="iPhone" and z=="Yes" and y=="No" and w=="Yes"):
print ("Charge your mobile device and if it's still not working you've probably damaged it from when you dropped it. Either contact an Engineer or buy a new phone.")
elif (x=="iPhone" and z=="No" and y=="No" and w=="Yes"):
print ("Try to charge your mobile device if that doesn't work contact a professional.")
elif (x=="iPhone" and z=="No" and y=="Yes" and w=="Yes"):
print ("Contact a mobile engineer to see if you've damaged your mobile device.")
elif (x=="iPhone" and z=="No" and y=="Yes" and w=="No"):
print("Take your phone to an Engineer to either fix your screen or get a new one.")

elif (x=="Android" and z=="Yes" and y=="No" and w=="No"):
print ("Start off by trying to recharge your device, if that's not the problem you've probably damaged your device and should contact a Engineer.")
elif (x=="Android" and z=="Yes" and y=="Yes" and w=="No"):
print ("Check if your Android charger has been damaged and if that's not the case contact your local Engineer.")
elif (x=="Android" and z=="Yes" and y=="No" and w=="Yes"):
print ("Try charging it to see if it has run out of battery and if it's still not working you've damaged your device and should contact a Engineer.")
elif (x=="Android" and z=="No" and y=="No" and w=="No"):
print ("Try to recharge your device, if that doesn't help contact a Engineer.")
elif (x=="Android" and z=="No" and y=="Yes" and w=="No"):
print ("You should contact your nearest Android Engineer.")
elif (x=="Android" and z=="No" and y=="No" and w=="Yes"):
print ("Charge your mobile device and if it's still not working contact a Engineer")

elif (x=="Windows" and z=="Yes" and y=="No" and w=="No"):
print ("Charge your mobile device and if it's not working contact an Engineer.")
elif (x=="Windows" and z=="Yes" and y=="Yes" and w=="No"):
print ("You've entered Yes to dropping it which probably means you've damaged it in one way or another and should contact an Engineer.")
elif (x=="Windows" and z=="Yes" and y=="No" and w=="Yes"):
print ("Start by charging your device and if it's not working take your phone to an Engineer.")
elif (x=="Windows" and z=="No" and y=="No" and w=="No"):
print ("Charge your device and if it's not working take your phone to an Engineer.")
elif (x=="Windows" and z=="No" and y=="Yes" and w=="No"):
print ("Take your mobile device to a local Engineer")
elif (x=="Windows" and z=="No" and y=="No" and w=="Yes"):
print ("Try charging your device and if it's not working contact an Engineer")
else:
print ("You didn't input valid information")

print ("")
print ("Thanks for using our troubleshooting service")

`


#2

@kappa123inthechat,

x => mobile-name
z => did you drop
y => did you try charging
w => is screen working

                   0        1        2
W  A  I  z y w  Windows  Android  IPhone
x  x  x  y n n   CH_E     TCH_E    TCH_E
x  x  x  y y n   DROP_E   CCH_E    E
x  x  x  y n y   SCH_E    TCH_E    CH_E_BN
x  x  x  n n y   TCH_E    CH_E     TCH_E
-  -  x  n y y   NO_T     NO_T     TCH_E
x  x  x  n y n   TTE      CH_E     E_FS_BN
-  -  -  y y y   NO_T     NO_T     NO_T
x  x  -  n n n   CH_E     TCH_E    NO_T

CH_E = "Charge the Phone, when no result go to Engineer."
TCH_E = "Try to charge the Phone, when no result go to Engineer." 
DROP_E = "You dropped your Phone, go to Engineer."
CCH_E = "Change charger, when no result go to Engineer."
E = "Go to Engineer."
SCH_E = "Start charging when no result go to Engineer."
CH_E_BN = "Charge your Phone, when no result go to Engineer or buy new."
NO_T = "No text."
TTE = "Try to contact Engineer."
E_FS_BN = "Go to Engineer or fix screen or buy new."

choice_to_text = {
ynn:  [CH_E,TCH_E,TCH_E],
yyn:  [DROP_E,CCH_E,E],
yny:  [SCH_E,TCH_E,CH_E_BN],
nny:  [TCH_E,CH_E,TCH_E],
nyy:  [NO_T,NO_T,TCH_E],
nyn:  [TTE,CH_E,E_FS_BN],
yyy:  [NO_T,NO_T,NO_T],
nnn  [CH_E,TCH_E,NO_T]
}
valid_phones=["windows","android","iphone"]

=============================================

the Resulting code

# possible phones
valid_phones=["windows","android","iphone"]

#all text's as variable
CH_E = "Charge the Phone, when no result go to Engineer."
TCH_E = "Try to charge the Phone, when no result go to Engineer." 
DROP_E = "You dropped your Phone, go to Engineer."
CCH_E = "Change charger, when no result go to Engineer."
E = "Go to Engineer."
SCH_E = "Start charging when no result go to Engineer."
CH_E_BN = "Charge your Phone, when no result go to Engineer or buy new."
NO_T = "No text."
TTE = "Try to contact Engineer."
E_FS_BN = "Go to Engineer or fix screen or buy new."

#possible answers to given-text-in-your-code
choice_to_text = {
"ynn":  [CH_E,TCH_E,TCH_E],
"yyn":  [DROP_E,CCH_E,E],
"yny":  [SCH_E,TCH_E,CH_E_BN],
"nny":  [TCH_E,CH_E,TCH_E],
"nyy":  [NO_T,NO_T,TCH_E],
"nyn":  [TTE,CH_E,E_FS_BN],
"yyy":  [NO_T,NO_T,NO_T],
"nnn":  [CH_E,TCH_E,NO_T]
}

#x=input ('What type of mobile device do you own? ').lower()
x="windows"
print valid_phones.index(x)
index_found=False
for i, j in enumerate(valid_phones):
    if j == x:
        index_nr=i
        index_found=True
combined_answer="yyn"
if index_found:
    z="Yes".lower()[0]
    y="yes".lower()[0]
    w="No".lower()[0]
    print z
    #z=input('Have you dropped your mobile device?(Yes/No)').lower()[0]
    #y=input ('Have you tried charging it?(Yes/No)').lower()[0]
    #w=input ('Is your screen working?(Yes/No)').lower()[0]
    combined_answer=z+y+w
    print choice_to_text[combined_answer][index_nr]
else:
    print "no valid phone"

Reference
http://stackoverflow.com/questions/176918/finding-the-index-of-an-item-given-a-list-containing-it-in-python
http://stackoverflow.com/questions/6797984/how-to-convert-string-to-lowercase-in-python


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.