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!