Why does my code not work?

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

31 Replies - 1297 Views - Last Post: 07 May 2014 - 08:37 AM Rate Topic: -----

#1 iLewisssHD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 07-May 14

Why does my code not work?

Posted 07 May 2014 - 03:21 AM

def bookingsystem():
    RowE = ["AE0","NE1","NE2","NE3","AE4","AE5","NE6","NE7","NE8","NE9"]
    RowD = ["AD0","AD1","AD2","ND3","AD4","AD5","AD6","AD7","AD8","AD9"]
    RowC = ["AC0","NC1","NC2","NC3","AC4","AC5","NC6","NC7","NC8","NC9"]
    RowB = ["AB0","NB1","NB2","NB3","AB4","AB5","AB6","NB7","AB8","AB9"]
    RowA = ["NA0","NA1","NA2","AA3","AA4","AA5","NA6","AA7","AA8","AA9"]

    rowchosen = input("Please choose a row you would like to sit in: ")
    seatsneeded = (int(input("How many seats do you need? "))

    if rowchosen == "A" or "B" or "C" or "D" or "E" and seatsneeded > 0 and seatsneeded < 7:
                   print("")

    if rowchosen == "A":
        freeseats = []
        maxavailable = []

        for seats in RowA:
            if seats[0] != "A":
                maxavailable = []

            else:
                maxavailable.append(seats[1:])

                if len(maxavailable) < len(seatsneeded):
                    freeseats = maxavailable

        if seatsneeded > len(maxavailable):
            print ("There isn't a block of that size available")
            print ("There is a block of", len(maxavailable),"seats available")
        else:
            print("There are enough seats")
            if seatsneeded == 1:
                print ("seats available from " + maxavailable[0])
            else:
                print ("seats available from " + maxavailable[0] + " - " + maxavailable[seatsneeded-1])
    else:
        print("No number of seats or row number entered, please try again ")
        bookingsystem()


Is This A Good Question/Topic? 0
  • +

Replies To: Why does my code not work?

#2 Robbss  Icon User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 55
  • Joined: 26-December 10

Re: Why does my code not work?

Posted 07 May 2014 - 03:25 AM

What doesn't work?
Was This Post Helpful? 1
  • +
  • -

#3 iLewisssHD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 07-May 14

Re: Why does my code not work?

Posted 07 May 2014 - 03:27 AM

View PostRobbss, on 07 May 2014 - 03:25 AM, said:

What doesn't work?


The 11th row at the end says 'Invalid Syntax'
Was This Post Helpful? 0
  • +
  • -

#4 Robbss  Icon User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 55
  • Joined: 26-December 10

Re: Why does my code not work?

Posted 07 May 2014 - 03:35 AM

Or means that either (Expression 1) Or (Expression 2) are true, you're using it incorrectly as you cannot check if "B" is either true or false, so you need to do the check you do first for each Or.
Was This Post Helpful? 1
  • +
  • -

#5 iLewisssHD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 07-May 14

Re: Why does my code not work?

Posted 07 May 2014 - 03:40 AM

View PostRobbss, on 07 May 2014 - 03:35 AM, said:

Or means that either (Expression 1) Or (Expression 2) are true, you're using it incorrectly as you cannot check if "B" is either true or false, so you need to do the check you do first for each Or.


Would this work?

    if rowchosen == "A" or rowchosen == "B" or rowchosen == "C" or rowchosen == "D" or rowchosen == "E":
                   if seatsneeded > 0 and seatsneeded < 7:
                   print("")

Was This Post Helpful? 0
  • +
  • -

#6 Robbss  Icon User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 55
  • Joined: 26-December 10

Re: Why does my code not work?

Posted 07 May 2014 - 03:40 AM

Yeah, that should be correct.
Was This Post Helpful? 1
  • +
  • -

#7 iLewisssHD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 07-May 14

Re: Why does my code not work?

Posted 07 May 2014 - 03:43 AM

View PostRobbss, on 07 May 2014 - 03:40 AM, said:

Yeah, that should be correct.


Nah, it doesn't, still says 'Invalid Syntax' at the end of that line
Was This Post Helpful? 0
  • +
  • -

#8 Robbss  Icon User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 55
  • Joined: 26-December 10

Re: Why does my code not work?

Posted 07 May 2014 - 03:47 AM

Try to put ( ) around each expression
Was This Post Helpful? 1
  • +
  • -

#9 iLewisssHD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 07-May 14

Re: Why does my code not work?

Posted 07 May 2014 - 03:49 AM

View PostRobbss, on 07 May 2014 - 03:47 AM, said:

Try to put ( ) around each expression


I did it like this and it didn't work

    if (rowchosen == "A") or (rowchosen == "B") or (rowchosen == "C") or (rowchosen == "D") or (rowchosen == "E"):

Was This Post Helpful? 0
  • +
  • -

#10 Robbss  Icon User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 55
  • Joined: 26-December 10

Re: Why does my code not work?

Posted 07 May 2014 - 03:58 AM

I'm not that familiar with Python, but try to change the input() to raw_input()
Was This Post Helpful? 1
  • +
  • -

#11 iLewisssHD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 07-May 14

Re: Why does my code not work?

Posted 07 May 2014 - 04:00 AM

View PostRobbss, on 07 May 2014 - 03:58 AM, said:

I'm not that familiar with Python, but try to change the input() to raw_input()


Doesn't come up in purple so doesn't detect as correct code
This is really bugging me now :(
Was This Post Helpful? 0
  • +
  • -

#12 Robbss  Icon User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 55
  • Joined: 26-December 10

Re: Why does my code not work?

Posted 07 May 2014 - 04:15 AM

I just tried this myself, and it worked perfectly fine:

invariable = input("input here: ");

if (invariable == "A") or (invariable == "B"):
	print("works");
else:
	print("no works");


Was This Post Helpful? 1
  • +
  • -

#13 iLewisssHD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 07-May 14

Re: Why does my code not work?

Posted 07 May 2014 - 04:18 AM

View PostRobbss, on 07 May 2014 - 04:15 AM, said:

I just tried this myself, and it worked perfectly fine:

invariable = input("input here: ");

if (invariable == "A") or (invariable == "B"):
	print("works");
else:
	print("no works");



I'm going to try and rewrite the code in another doc and ill let you know the result,
Thanks
Was This Post Helpful? 0
  • +
  • -

#14 Robbss  Icon User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 55
  • Joined: 26-December 10

Re: Why does my code not work?

Posted 07 May 2014 - 04:18 AM

Could you post your modified code, because I cannot reproduce your issue, what I've made works perfectly fine.
Was This Post Helpful? 0
  • +
  • -

#15 iLewisssHD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 07-May 14

Re: Why does my code not work?

Posted 07 May 2014 - 04:20 AM

This is my code now:

def bookingsystem():
    RowE = ["AE0","NE1","NE2","NE3","AE4","AE5","NE6","NE7","NE8","NE9"]
    RowD = ["AD0","AD1","AD2","ND3","AD4","AD5","AD6","AD7","AD8","AD9"]
    RowC = ["AC0","NC1","NC2","NC3","AC4","AC5","NC6","NC7","NC8","NC9"]
    RowB = ["AB0","NB1","NB2","NB3","AB4","AB5","AB6","NB7","AB8","AB9"]
    RowA = ["NA0","NA1","NA2","AA3","AA4","AA5","NA6","AA7","AA8","AA9"]

    rowchosen = input("Please choose a row you would like to sit in: ")
    seatsneeded = (int(input("How many seats do you need? "))

    if (rowchosen == "A") or (rowchosen == "B") or (rowchosen == "C") or (rowchosen == "D") or (rowchosen == "E"):
                   if seatsneeded > 0 and seatsneeded < 7:
                   print("")

    if rowchosen == "A":
        freeseats = []
        maxavailable = []

        for seats in RowA:
            if seats[0] != "A":
                maxavailable = []

            else:
                maxavailable.append(seats[1:])

                if len(maxavailable) < len(seatsneeded):
                    freeseats = maxavailable

        if seatsneeded > len(maxavailable):
            print ("There isn't a block of that size available")
            print ("There is a block of", len(maxavailable),"seats available")
        else:
            print("There are enough seats")
            if seatsneeded == 1:
                print ("seats available from " + maxavailable[0])
            else:
                print ("seats available from " + maxavailable[0] + " - " + maxavailable[seatsneeded-1])
    else:
        print("No number of seats or row number entered, please try again ")
        bookingsystem()

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3