Calling variables from within seperate IF statements

Hi there :slight_smile:.

Link to my work: https://gist.github.com/c1e9ee2c00d52e3f4184386ceef55346

I am currently on a task on Codecademy exploring IF statements, and am currently trying to expand on the basics, as I feel competent with the idea already.

I am currently making a function where I have to show the best option for the user, depending on what the cheapest option is, however am unable to call the numeric value from either of my functions (ground_shipping and drone_shipping).

As I have put a string in both return’s, I am looking for another way that I can just call the cost when needed, rather than calling the entire string.

I have attempted to call it in my bottom function, but to no success.

What is the easiest way I can achieve this outcome?

Cheers.

Why do drone and ground shipping functions return a string? we need these function to calculate the cost.

if you want to print pretty, i would recommend making a separate function for that.

1 Like

Hi there.

Cheers for the help.

Yeah I made the drone and ground shipping return strings before I realised that the data would be used again in a later function.

I will most likely change it to how it’s supposed to be, in order to get the result needed.

But if I were to attempt what I was saying, by calling the cost variable without calling the string, what would be the easiest way of doing so? Just out of interest and expanding my knowledge. :slight_smile:

Cheers.

You could use a regex to extract the number from the string? But i wouldn’t go there. Given we need the cost, you should just hand the cost back, and make a separate function to print pretty.

1 Like