4 Replies - 819 Views - Last Post: 03 January 2010 - 01:41 PM Rate Topic: -----

#1 blur959  Icon User is offline

  • New D.I.C Head

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

Problem with if statements

Post icon  Posted 31 December 2009 - 01:46 AM

Hi, all, i would like to know if is there anything wrong with my code, because the if statements in my code doesnt seem to work.
thanks!

# print schedule of flights to paris and ask user for input
		paris_flights_menu = schedule_of_flights_paris()


		# If user choose 1.(Paris via Egypt)
		if paris_flights_menu == "1":
			flight_paris_via_egypt()
			signing_off()


def schedule_of_flights_paris():
	paris_flights_menu = raw_input(("There are 2 flights going to Paris.\n"
			" 1: Via Egypt\n"
			" 2: Direct to Paris\n\n"
			"Please choose your prefered flights "
			"by pressing 1 or 2 "))

	print 'Flight Chosen', paris_flights_menu

def flight_paris_via_egypt():
	print " blablabla "



Is This A Good Question/Topic? 0
  • +

Replies To: Problem with if statements

#2 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5310
  • View blog
  • Posts: 27,210
  • Joined: 10-May 07

Re: Problem with if statements

Posted 31 December 2009 - 02:18 AM

View Postblur959, on 31 Dec, 2009 - 02:46 AM, said:

because the if statements in my code doesnt seem to work.

Can you give a little more detail?

What would consider working?

Also, is this Perl or Python?
Was This Post Helpful? 0
  • +
  • -

#3 blur959  Icon User is offline

  • New D.I.C Head

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

Re: Problem with if statements

Posted 31 December 2009 - 03:20 AM

View Postblur959, on 31 Dec, 2009 - 12:46 AM, said:

Hi, all, i would like to know if is there anything wrong with my code, because the if statements in my code doesnt seem to work.
thanks!

# print schedule of flights to paris and ask user for input
		paris_flights_menu = schedule_of_flights_paris()


		# If user choose 1.(Paris via Egypt)
		if paris_flights_menu == "1":
			flight_paris_via_egypt()
			signing_off()


def schedule_of_flights_paris():
	paris_flights_menu = raw_input(("There are 2 flights going to Paris.\n"
			" 1: Via Egypt\n"
			" 2: Direct to Paris\n\n"
			"Please choose your prefered flights "
			"by pressing 1 or 2 "))

	print 'Flight Chosen', paris_flights_menu

def flight_paris_via_egypt():
	print " blablabla "



Okay, its python by the way.
My script is kind of lengthy that is why.Below, is it.
"""
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 and if none is chosen
	country = choose_destination()
	if country is None:
		return

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

		# print schedule of flights to paris and ask user for input
		paris_flights_menu = schedule_of_flights_paris()


		# If user choose 1.(Paris via Egypt)
		if paris_flights_menu == "1":
			flight_paris_via_egypt()
			signing_off()

		# If user choose 2.(Paris Direct)
		elif paris_flights_menu == '2':
			flight_paris_direct()
			signing_off

		# If neither of flights to Paris is chosen
		else:
			neither_flights_selected_paris()
			signing_off()



	# Signing off
	signing_off()

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

def intro_message():
	print "%s\n%s\n%s" % ("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.\n")

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 country

def schedule_of_flights_paris():
	paris_flights_menu = raw_input(("There are 2 flights going to Paris.\n"
			" 1: Via Egypt\n"
			" 2: Direct to Paris\n\n"
			"Please choose your prefered flights "
			"by pressing 1 or 2 "))

	print 'Flight Chosen', paris_flights_menu

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

def flight_paris_direct(paris_flights_menu):
	 print "%s\n%s" % ("The next flight is at 2300hours and ",
	"arrival time will be the following morning at 0935hours ")

def neither_flights_selected_paris(paris_flights_menu):
	print " May i know where you want to go?, Or maybe you want to try again? "

def signing_off():
	print "%s\n%s\n%s" % ("Thank you for using the flight schedule program to ",
	"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()


Was This Post Helpful? 0
  • +
  • -

#4 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,788
  • Joined: 20-September 08

Re: Problem with if statements

Posted 31 December 2009 - 10:30 PM

I ran this online at

http://ideone.com/FiadGd8X

so see # comments #

to fix to run with user input from your PC running Python


This quick fix may help get you started ...

Shalom,

David



"""
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 and if none is chosen
	country = choose_destination()
	if country is '':
		print "You didn't choose a county ... "
		return
 
	# if 'a' (for Paris) is chosen
	if country.lower() == "a":
 
		# print schedule of flights to paris and ask user for input
		paris_flights_menu = schedule_of_flights_paris()
 
		# If user choose 1.(Paris via Egypt)
		if paris_flights_menu == "1":
			flight_paris_via_egypt()
 
		# If user choose 2.(Paris Direct)
		elif paris_flights_menu == '2':
			flight_paris_direct()
 
		# If neither of flights to Paris is chosen
		else:
			neither_flights_selected_paris()
 
	# Signing off
	signing_off()
 
 
def welcome_message():
	print "Welcome to Singapore Changi Airport,\n" \
	"departure hall, terminal 3!"
 
def intro_message():
	print "\nThis schedule is to assist you in finding the correct\n" \
	"flight departing time and the flight schedules of the\n" \
	"other flights flying to the designated countries.\n"
 
def choose_destination():
	prompt = '''	a: Paris
	b: Los Angeles
	c: Dawin
Please choose a, b or c : '''
	#  comment out the next 2 lines #
	print prompt, 'a'
	return 'a'
	#return raw_input( prompt ) # uncomment this line #
 
def schedule_of_flights_paris():
	prompt = '''\nThere are 2 flights going to Paris.
	1: Via Egypt
	2: Direct to Paris
Please choose 1 or 2 : '''
	#  comment out the next 2 lines #
	print prompt, '2'
	return '2'
	#return raw_input(prompt ) # uncomment this line #
 
def flight_paris_via_egypt():
	print "\nThe next flight is at 1750 hours and the arrival\n" \
	"time will be the following morning at 1130 hours."
 
def flight_paris_direct():	 
	print "\nThe next flight is at 2300 hours and the arrival\n" \
	"time will be the following morning at 0935 hours."
 
def neither_flights_selected_paris():
	print "\nMay I know where you want to go? Or, maybe you want to try again?"
 
def signing_off():
	print "\nThank you for using the flight schedule program to " \
	"check out your flights.\n" \
	"We sincerely hope that it will be of some use to you.\n" \
	"Have a nice day and a pleasant and safe flight.\n"
 
 
flight_schedule()


This post has been edited by David W: 31 December 2009 - 10:31 PM

Was This Post Helpful? 0
  • +
  • -

#5 Tshiknn  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 20
  • Joined: 18-October 09

Re: Problem with if statements

Posted 03 January 2010 - 01:41 PM

Your function schedule_of_flights_paris() returns nothing. Therefore, the value of paris_flights_value is None. Simply put the statement "return paris_flights_menu" at the end of schedule_of_flights_paris().
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1