2 Replies - 1072 Views - Last Post: 24 December 2009 - 01:19 PM Rate Topic: -----

#1 blur959  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 20-December 09

Program for a flight schedule 2

Post icon  Posted 23 December 2009 - 05:22 AM

Hi all. This is a follow-up of my previous post. I edited my existing script thanks to the comment given. But however, i have encountered some more problems with my script and i have no idea what is wrong and how to correct it. I hope you guys out there will give me some suggestions and help me with it. I will appreciate it.
Thanks in advance!
Problems faced:
1) Firstly, i have no idea why all of my if statements are not working.
2)I wanted to run a particular function and after running it i want it to end, but however it continues throughout my entire script.
3) I am not sure if my for loop is used and typed correctly.Hope you guys can correct me(:

Sorry guys, i know its kind of lengthy, hope you guys could take out some time to look at it.
I will appreciate it!
Thanks:)


"""
This is a program about a flight schedule for flights to Paris, Los Angeles,
Dawin
"""

def flight_schedule():
	"""
	Flight schedule for flights to Paris, Los Angeles, Dawin
	"""

	# Greet the user
	welcome_message()

	# Introduce the program to the user and state what it does
	intro_message()

	# Ask the user to choose a destination
	country = choose_destination()
	if country is None:
		try:
			country/0
		except:
			print "May i know where you intend to go? "

	# if a(Paris) is chosen
	if country.lower() is "a":
		paris_flight_schedule()


	# If b(Los_Angeles) is chosen
	elif country.lower() is "b":
		los_angeles_flight_schedule()


	# if both a and b is not chosen
	elif country.lower() is "c":
		dawin_flight_schedule()

	# if neither is selected
	if country == None:
		return

	# FLight schedule of different flights going to Paris
	choose_flight_paris = paris_flight_schedule()

	# If none of the flights is chosen
	choose_flight_paris = raw_input(("Please choose your prefered flights by "
									 "pressing 1 or 2 "))

	if choose_flight_paris is None:
		return None

	# For loop for Paris flights
	available_flights = ["1: Paris via Egypt", "2: Paris Direct"]
	chosen_flight = []
	for chosen_flight_name in available_flights:
		if "1: Paris via Egypt" in chosen_flight_name:
			chosen_flight.append(chosen_flight_name)

	print chosen_flight_name

	# If Flight to Paris via Egypt is chosen
	if choose_flight_paris == 1:
		flight_paris_via_egypt()
		signing_off()

	# If Flight to Paris direct is chosen
	elif choose_flight_paris == 2:
		flight_paris_direct()
		signing_off()

	# FLight schedule of different flights going to Los Angeles
	choose_flight_los_angeles = los_angeles_flight_schedule()

	  # If None of the flights is chosen
	choose_flight_los_angeles = raw_input(("Please choose your prefered flights "
									 "by pressing 1 or 2 "))

	if choose_flight_los_angeles == None:
		return None

	# If flight to Los Angeles is chosen
	if choose_flight_los_angeles == 1:
		flight_los_angeles_direct()
		signing_off()

	# Flight schedule of different flights going to Dawin
	choose_flight_dawin = dawin_flight_schedule()

	# If None of the flights is chosen
	choose_flight_dawin = raw_input(("Please choose your prefered flights "
									 "by pressing 1 or 2 "))

	if choose_flight_dawin == None:
		return None

	# If flight to Dawin via China
	if choose_flight_dawin == 1:
		flight_dawin_via_china()

	# If flight to Dawin via Canberra
	elif choose_flight_dawin == 2:
		flight_dawin_via_canberra()



	# Signing off
	signing_off()



def welcome_message():
	print " Welcome to Singapore Changi Airport, "
	"departure hall, terminal 3!"


def intro_message():
	print " This schedule is to assist you in finding the correct "
	"flight departing time and the flight "
	"schedules of the other flights flying to the designated countries."


def choose_destination():
	country = raw_input(("Please choose a country given below.\n"
				" a: Paris\n"
				" b: Los Angeles\n"
				" c: Dawin\n\n" ))

	return ("You have just chosen, "+ country +"")

def paris_flight_schedule():
	print ("There are 2 flights going to Paris.\n"
				" 1: Via Egypt\n"
				" 2: Direct to Paris\n" )

def flight_paris_via_egypt():
	print ("The next flight is at 1750hours and "
		"arrival time will be the following morning at 1130 hours ")

def flight_paris_direct():
	 print ("The next flight is at 2300hours and "
		"arrival time will be the following morning at 0935hours ")


def los_angeles_flight_schedule():
	print ("There are 1 flight going to Los Angeles.\n"
				" 1: Direct to Los Angeles\n" )

def flight_los_angeles_direct():
	print ("The next flight is at 1130 hours next "
		"morning and arrival time will be 1950 hours. ")


def dawin_flight_schedule():
	print ("There are 2 flights going to Dawin.\n"
				" 1: Via China\n"
				" 2: Via Canberra\n" )

def flight_dawin_via_china():
	print ("The next flight is at 1600hours and the "
		"arrival time will be the following afternoon at 0250hours. ")

def flight_dawin_via_canberra():
	  print ("The next flight will be the following "
		"afternoon 1250hours and the "
		"arrival time will be the following afternoon at 2200hours. ")


def signing_off():
	print ("Thanks for using the flight schedule program too check out "
	" your flights, We sincerely hope that it will be of some use "
	" to you.Have a nice day and a pleasant and safe flight.\n\n ")

	end_statement = raw_input(("Press Enter to continue checking other "
							" flights or type quit to exit "))

	if "quit" in end_statement.lower():
		return None
	else:
		flight_schedule()


flight_schedule()




Is This A Good Question/Topic? 1
  • +

#3 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2870
  • View blog
  • Posts: 11,025
  • Joined: 15-July 08

Re: Program for a flight schedule 2

Posted 24 December 2009 - 09:33 AM

1) Your if statement looks like this:
country = choose_destination()
...
if country.lower() is "a":
		paris_flight_schedule()



Which is perfectly legitimate. However, your function choose_destination(), does not return a, b, or c. It returns this:
def choose_destination():
	country = raw_input(("Please choose a country given below.\n"
				" a: Paris\n"
				" b: Los Angeles\n"
				" c: Dawin\n\n" ))

	return ("You have just chosen, "+ country +"") #<--- Returns the FULL string, not just answer.



You can fix THAT issue by doing something like this:
def choose_destination():
	while(True): # Check to make sure they entered a, b, or c
		country = raw_input(("Please choose a country given below.\n"
				" a: Paris\n"
				" b: Los Angeles\n"
				" c: Dawin\n\n" ))  
		country = country.lower() # Make it lowercase
		if  not (country == 'a' or country == 'b' or country == 'c'):
			print 'Try again...'
		else:
			break
   print 'You chose', country
   return country



2) Do you mean, like this?
	if country is "a":
		paris_flight_schedule()
		return 


	# If b(Los_Angeles) is chosen
	elif country "b":
		los_angeles_flight_schedule()
		return


	# if both a and b is not chosen
	elif country is "c":
		dawin_flight_schedule()
		return

	# Not needed anymore, as it returns a correct value
	#if country == None:
	#	return



3) I'm kind of confused as to what is happening after this...you may with to tidy all of that up a bit.
Was This Post Helpful? 1
  • +
  • -

#4 dave_6_10  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 19-March 08

Re: Program for a flight schedule 2

Posted 24 December 2009 - 01:19 PM

I do like the concept of what your doing with this, and I am sure you intend to add many more flight schedules to make it more comprehensive when you get the code stabilized.

Wish I could be more assistance to you than to just say if you need help converting it to Py3K then I can help with that.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1