-2

I wrote a function that is meant to tell you in which cost segment the user is depening on the day and hour entered by the user itself.

Everything seems to work pretty fine but I don't quite understand why the function is returning a None output after the correct and expected output.

Please see my code below:

day = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
hour = list(range(0, 24))
segments = {'Cheap': hour[:8], 'Intermediate': hour[8:10] + hour[14:18] + hour[22:], 'Costly': hour[10:14] + hour[18:22]} 
dayEvaluate = "z"
hourEvaluate = 25
#Let's define the function:
def power_price_calculator(dayEvaluate, hourEvaluate):
    while (dayEvaluate not in day): 
        dayEvaluate = input('Enter the day you want to check: ')
        if dayEvaluate not in day:
            print('Please, enter a valid day name (Monday-Sunday)')
    if dayEvaluate in day[:4]:
        while (hourEvaluate not in hour):
            hourEvaluate = int(input('Enter the hour you want to check: '))
            if((hourEvaluate > 24) or (hourEvaluate < 0)): 
                print('Please, enter a valid hour (0-24h)')
            if hourEvaluate in segments['Cheap']:
                print('Congratulations! You are in the cheap segment')
            elif hourEvaluate in segments['Intermediate']: 
                print('It is OK, you are in the intermediate segment')
            elif hourEvaluate in segments ['Costly']: 
                print('Beware of your consumption, you are in the costly segment')
    else: 
        print('Congratulations! You are in the cheap segment')

        
print(power_price_calculator(dayEvaluate, hourEvaluate))

Could anyone shed some light on this?

Thank you very much!

MadMarx17
  • 71
  • 7
  • What were you expecting the function to return? That is the first question you should ask yourself, given that I do not see a natural output it. The function is called `power_price_calculator`, but there is no real calculation going on, just an identification of a price segment (with no price attached to it) – nikeros Oct 25 '21 at 09:45

1 Answers1

1

Split your problem like this:

result = power_price_calculator(dayEvaluate, hourEvaluate) # result is None
print(result) # Does not print anything

It's because your function only prints data, it does not return anything

Be Chiller Too
  • 2,502
  • 2
  • 16
  • 42