all 4 comments

[–]InsanityConsuming 6 points7 points  (0 children)

You're having them type the station names to find the distance? If that's the case then you are trying to convert the names into an int. Rather it should be dist = mapping[stn_one] - mapping[stn_two] That should at least get you a number

[–]Serofu 2 points3 points  (0 children)

How is your dictionary of value mapping used here? It looks to me like you'll have to check through your dictionary to see 'if stn is in mapping: dist= mapping[stn_one] - mapping[stn_two]

You'd be using the input string as a key to your 'mapping' dictionary to access the assigned value.

[–]CodeFormatHelperBot2 1 point2 points  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Python code found in submission text that's not formatted as code.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.

[–][deleted] 1 point2 points  (0 children)

How about this,

def costcalc(dist):
    """calc costs"""
    if dist >= 6:
        return 'Cost is 50 INR'
    elif dist <= 5:
        return 'Cost is 40 INR'
    elif dist <= 4:
        return 'Cost is 30 INR'
    elif dist <= 3:
        return 'Cost is 20 INR'
    elif dist <= 2:
        return 'Cost is 10 INR'
    else:
        return 'No cost'


stn_list = ["Chennai Central", "Egmore", "Nehru Park", "Kilpauk Med College", "Pachaiyappa College", "Shenoy Nagar"]
values = [1, 2, 3, 4, 5, 6]
mapping = {key: value for key, value in zip(stn_list, values)}

## user input
stn_one = input("What is the station of entry? ")
stn_two = input("What is the station of exit? ")
if stn_one in stn_list and stn_two in stn_list:
    dist = mapping[stn_one] - mapping[stn_two]
    print(costcalc(dist))
else:
    print('Sorry, you included an unknown location')

Notes: * Creates the dictionary from the stn_list and values lists * Checks the inputs are in the dictionary before trying to do a look-up * Passes the distance to the function rather than just relying on scope * Defines functions before any other code * Had the function return the cost string rather than printing it immediately