Skip to content Skip to sidebar Skip to footer

Python | Skipping A User_input

I have a problem with my python script as when this question comes up: ('Is there problem with the software or hardware? ') When I type in 'Software' my first software question co

Solution 1:

(1) Think about what if clauses do.

(2) Make sure you understand what tabs/spaces do in python.

Here is how to do it:

phone2 = input("Is there problem with the software or hardware? ") 
ifphone2== "Software"orphone2== "software":
    s1 = input("Is your phone freezing/stuttering? ")
    ifs1== "Yes"ors1== "yes" :
       print("Try deleting some apps and this might help with your problem")
ifphone2== "Hardware"orphone2== "hardware" :
   h1 = input("Does your phone switch on? ")
   ifh1== "No"orh1== "no" :
      print("There might be a issue with your battery.")

Solution 2:

The problem was that you did not use proper indentations after your if statements ,hence the rest of your code was executed anyway:

phone2 = input("Is there problem with the software or hardware? ") #Questionif phone2 == "Software"or phone2 == "software" :
    deffoo():
        whileTrue:
             returnFalse
    s1 = input("Is your phone freezing/stuttering? ")
    if s1 == "Yes"or s1 == "yes":
        print("Try deleting some apps and this might help with your problem")
    if s1 == "No"or s1 == "no":
        deffoo():
            whileTrue:
                returnFalseif phone2 == "Hardware"or phone2 == "hardware":
    deffoo():
        whileTrue:
            returnFalse
    h1 = input("Does your phone switch on? ")
    if h1 == "No"or h1 == "no":
        print("There might be a issue with your battery. I recommend replacing it with the help of a specialist")
    if h1 == "Yes"or h1 == "yes":
        deffoo():
            whileTrue:
                returnFalse

PS: (I don't think you need that "foo" function in there.)

Post a Comment for "Python | Skipping A User_input"