Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I was trying to build a booking system but this if statement is working quite well,

i require your assistance..

As if the input choice is equal to travel_sites it should execute the code below it. But instead of thaat the python is executing the else statement...

Python
print("A Platfrom for the people who love travelling...")

travel_sites = {
     "Kashmir to Jammu" : [18,4],
    "Jammu to Kashmir" : [18,5],
    "Kashmir to San Fransisco" : [15,1],
    "Kashmir to Iceland" : [18,2]
}

choice = input("Enter the site you wanna to go and from where you wanna go ? = ").title()

if choice in travel_sites:
	age = input("Enter you,r age")
	if age <= choice[1]:
		print(f"Well, we booked you,r ticket from {choice}")

else:
	print("Well we don,t have that")

As if the input choice is equal to travel_sites it should execute the code below it. But instead of thaat the python is executing the else statement...

What I have tried:

I tried to to write the input in commas but it did,nt worked.
Posted
Updated 16-Dec-18 8:53am
v3

choice in travel_sites will never be true because you transform the input to Title Case while the elements of travel_sites are not title case itself. .title() transforms a possible input to Kashmir To Jammu whereas what's in travel_sites is Kashmir to Jammu with to instead of To.
 
Share this answer
 
Comments
Member 14068174 17-Dec-18 0:39am    
Thanks bro...
i want some programming tips from you
Quote:
Why is this if statement no working

Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

27.3. pdb — The Python Debugger — Python 3.6.1 documentation[^]
Debugging in Python | Python Conquers The Universe[^]
pdb – Interactive Debugger - Python Module of the Week[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
 
Share this answer
 
Comments
Member 14068174 17-Dec-18 0:39am    
Thanks bro, i sloved it without debugger

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900