mercredi 10 avril 2019

My code isn't working, I'm sure I've made an obvious mistake but i can't see it. Can someone point it out for me? [duplicate]

This question already has an answer here:

When the code is run, the part of the code that works is the first section of the if statement, the else statement does not seem to affect the code i don't know why. This is the code:

def lemon(a, b):
try:
    week = [int(input(f'Please input data for week {a} for {b} for bus{chr(bus)}: ')) for bus in range(ord('A'), ord('F')+1)]
    return week
except ValueError:
    print("Not a number given.")
return None


 answer = input("Type 'F' if you want to use own data, do not type anything if you would like to use supplied data: ")

if answer == 'F' or 'f':

Week1 = lemon ('1', 'Monday')
Week2 = lemon ('1', 'Tuesday')
Week3 = lemon ('1', 'Wednesday')
Week4 = lemon ('1', 'Thursday')
Week5 = lemon ('1', 'Friday')


Week6 = lemon ('2', 'Monday')
Week7 = lemon ('2', 'Tuesday')
Week8 = lemon ('2', 'Wednesday')
Week9 = lemon ('2', 'Thursday')
Week10 = lemon ('2', 'Friday')


Week11 = lemon ('3', 'Monday')
Week12 = lemon ('3', 'Tuesday')
Week13 = lemon ('3', 'Wednesday')
Week14 = lemon ('3', 'Thursday')
Week15 = lemon ('3', 'Friday')


Week16 = lemon ('4', 'Monday')
Week17 = lemon ('4', 'Tuesday')
Week18 = lemon ('4', 'Wednesday')
Week19 = lemon ('4', 'Thursday')
Week20 = lemon ('4', 'Friday')

else:

Week1 = [0, 0, 2, 1, -1, 0]
Week2 = [0, 1, 0, 0, -1, -5]
Week3 = [0, 0, -1, 0, -1, -5]
Week4 = [2, 0, -1, 0, -2, -5]
Week5 = [2, 1, -2, 0, -4, -4] 


Week6 = [4, 2, -2, 0, -10, -3]
Week7 = [0, 0, -3, 0, -2, -5]
Week8 = [3, 0, -1, 0, 0, 0]
Week9 = [4, 0, 0, 0, 0, 0]
Week10 = [-2, 0, 0, 0, 0, 0] 


Week11 = [-5, 1, -2, 2, 0, 0]
Week12 = [0, 0, 0, 0, 1, -2]
Week13 = [0, 0, 1, 0, 2, -3]
Week14 = [3, 0, 1, 0, -3, 1]
Week15 = [4, 2, 1, 0, 1, 1]


Week16 = [-1, 0, 1, 0, 1, 1]
Week17 = [8, 0, -1, 0, 3, 0]
Week18 = [1, 1, -1, 0, -1, 0] 
Week19 = [1, 0, 2, 0, 0, -2]
Week20 = [-2, 0, -2, 0, 0, -5]

BUSA = [] weeks = 20

for week in range(1, weeks + 1): BUSA.append(globals()['Week{}'.format(week)][0])

print(BUSA)

The section of the code that doesn't seem to work:

answer = input("Type 'F' if you want to use own data, do not type anything if you would like to use supplied data: ")

if answer == 'F' or 'f':

Week1 = lemon ('1', 'Monday')
Week2 = lemon ('1', 'Tuesday')
Week3 = lemon ('1', 'Wednesday')
Week4 = lemon ('1', 'Thursday')
Week5 = lemon ('1', 'Friday')


Week6 = lemon ('2', 'Monday')
Week7 = lemon ('2', 'Tuesday')
Week8 = lemon ('2', 'Wednesday')
Week9 = lemon ('2', 'Thursday')
Week10 = lemon ('2', 'Friday')


Week11 = lemon ('3', 'Monday')
Week12 = lemon ('3', 'Tuesday')
Week13 = lemon ('3', 'Wednesday')
Week14 = lemon ('3', 'Thursday')
Week15 = lemon ('3', 'Friday')


Week16 = lemon ('4', 'Monday')
Week17 = lemon ('4', 'Tuesday')
Week18 = lemon ('4', 'Wednesday')
Week19 = lemon ('4', 'Thursday')
Week20 = lemon ('4', 'Friday')

else:

Week1 = [0, 0, 2, 1, -1, 0]
Week2 = [0, 1, 0, 0, -1, -5]
Week3 = [0, 0, -1, 0, -1, -5]
Week4 = [2, 0, -1, 0, -2, -5]
Week5 = [2, 1, -2, 0, -4, -4] 


Week6 = [4, 2, -2, 0, -10, -3]
Week7 = [0, 0, -3, 0, -2, -5]
Week8 = [3, 0, -1, 0, 0, 0]
Week9 = [4, 0, 0, 0, 0, 0]
Week10 = [-2, 0, 0, 0, 0, 0] 


Week11 = [-5, 1, -2, 2, 0, 0]
Week12 = [0, 0, 0, 0, 1, -2]
Week13 = [0, 0, 1, 0, 2, -3]
Week14 = [3, 0, 1, 0, -3, 1]
Week15 = [4, 2, 1, 0, 1, 1]


Week16 = [-1, 0, 1, 0, 1, 1]
Week17 = [8, 0, -1, 0, 3, 0]
Week18 = [1, 1, -1, 0, -1, 0] 
Week19 = [1, 0, 2, 0, 0, -2]
Week20 = [-2, 0, -2, 0, 0, -5]

Aucun commentaire:

Enregistrer un commentaire