Why isn't this code working?


#1

The code below isn't currently working. I don't know why it's not working and would like some assistance on why the code isn't answering the questions below.


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)')
#The part above is asking the questions that the user might have and below answering them with the users information given.

if(x=="Windows" "Android" "iPhone" 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" "Android" "iPhone" 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" "Android" "iPhone" 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" "Android" "iPhone" 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" "Android" "iPhone"and z=="No" and y=="Yes" and w=="No"):
    print ("Take your mobile device to a local Engineer")
elif (x=="Windows" "Android" "iPhone"and z=="No" and y=="No" and w=="Yes"):
    print ("Try charging your device and if it's not working contact an Engineer")
elif (x=="Windows" "Android" "iPhone" and z=="No" and y=="Yes" and w=="Yes"):
    print ("Go to an Engineer to see if your device is damaged on the inside.")
elif (x=="Windows" "Android" "iPhone" and z=="Yes" and y=="Yes" and w=="Yes"):
    print ("It doesn't sound like there is a problem with your mobile device but if you think there is contact an Engineer")
else:
    print ("You didn't input valid information")

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


#2

this looks pretty weird:

x=="Windows" "Android" "iPhone"

no or operators? use or operators:

x=="Windows" or x == "Android" or x == "iPhone"

but this is so much repeat, why not simply do:

if x=="Windows" or x == "Android" or x == "iPhone":
   // x, y, z and w options
else:
   print "unknown phone"

saves a lot of code. DRY, one of the fundamental principals of programming.

also, i would seriously make the comparison case insensitive, if the user now enters yes or YES instead of Yes, the comparison is evaluated to false (string comparison is case-sensitive.

you don't validate user input, that is very trusting of you (rule 1 when asking for input: never trust the end user)


#3

Oh ok. Thanks a lot.


#4

that should help you further, if you need more help, post an updated version of your code

But it would be really good for your coding skill, to do as much as possible yourself


#5

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