If and Else function

Question:

I need help with the following code.

phone = input("What is the make of your Phone? ")

if phone == "Samsung":
         model1 = input("Now can you tell me the model of your phone?")
         if model1 < int(4):
            print ("This model and any older models are not compatible with this system, Sorry for any inconvenience!")

         else:
             print ("Let us move on to the problem")


elif phone == "Apple":
        model2 = input("Now can you tell me the model of your phone?")
        if model1 < 4:
         print("This model and any older models are not compatible with this system, Sorry for any inconvenience!")

        else:
            print("Let us move on to your problem")

Can you tell me how I would make it so that when you type in anything less than 4 it would say “Model not compatible” and when it is above 4 it will carry on with the code. Thank you

This is what happens when I type a number in

What is the make of your Phone? Samsung
Now can you tell me the model of your phone?3
Traceback (most recent call last):
  File "\shs-homes0111275$GCSE ComputingMY TroubleShooting code.py", line 9, in <module>
    if model1 < int(4):
TypeError: unorderable types: str() < int()
Asked By: Usama Kareem

||

Answers:

The Problem is you didn’t convert model1 to int, it is a string in there and you can’t compare int to string.
try this:

if int(model1)<4

The same goes for the next else if of your’s

Answered By: Jonathan Weiss

Try to change

if model1 < int(4):

to

if int(model1) < 4:

and you would need exception handling with try as well.

Answered By: quantummind
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.