Home > Enterprise >  Why does my code repeat instead carry on when i input an integer?
Why does my code repeat instead carry on when i input an integer?

Time:09-30

it keeps repeating please help me

new_custom = ""
while new_custom !=["y","n"]:
    new_custom = input("are you a new customer y/n \n").lower
    if new_custom == "y":
        if miles <= 5:
            print (7)
        else:
            print( 7   ((miles - 5) * 2))
    elif new_custom == "n":
        if miles <= 5:
            print(8)
        else:
              print(8 ((miles-5)*2))

i cant figure out why it keeps repeating

CodePudding user response:

There are 2 errors present in your code:

new_custom !=["y","n"]

This does not check if a string is contained in the list; it checks to see if a list containing the same elements is present.

input("are you a new customer y/n \n").lower

By missing the brackets your script does not realise that lower is a function.

Using these 2 lines will correct your code:

while new_custom not in ["y","n"]:
    new_custom = input("are you a new customer y/n \n").lower()

CodePudding user response:

your while condition should be like this:

miles = 8
new_custom = ""
while new_custom not in ["y","n"]:
    new_custom = input("are you a new customer y/n \n").lower()
    if new_custom == "y":
        if miles <= 5:
            print (7)
        else:
            print( 7   ((miles - 5) * 2))
    elif new_custom == "n":
        if miles <= 5:
            print(8)
        else:
              print(8 ((miles-5)*2))
   

CodePudding user response:

You missed the parentheses on your lower case check. Should be .lower() and the code should continue but the next error will be miles is not defined.

  • Related