-1

The outcome of this is when you enter any number 1-7 you will get the day of that number. for some reason it will always prompt Monday. How can I fix this?

 '#Enter a number range 1-7 for the day of the week Example 1=Monday
#variables to represent the days of the week
num = float(input ("Enter the number for the day of week"))
Monday_number = 1
Tuesday_number = 2
Wednesday_number = 3
Thursday_number = 4
Friday_number = 5
Saturday_number = 6
Sunday_number = 7
Other_number = 8

#the day of the week
if Monday_number == 1:
print('Monday')
elif Tuesday_number == 2:
print('Tuesday')
elif Wednesday_number == 3:
print('Wednesday')
elif Thursday_number == 4:
print('Thursday')
elif Friday_number == 5:
print('Friday')
elif Saturday_number == 6:
print('Saturday')
elif Sunday_number == 7:
print('Sunday')
else:
if Other_number > 7:
    print('Invalid number entered')'
APerson
  • 8,140
  • 8
  • 35
  • 49

2 Answers2

1

You're not comparing num, the user input, to anything. In your if statements, you should be sequentially comparing num to each of the day of week constants. Better yet, you could be using a lookup table:

days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
user_input = input('Enter the day of the week: ')
print(days[int(user_input)])
APerson
  • 8,140
  • 8
  • 35
  • 49
1

Step through your algorithm mentally, line-by-line. What happens when you get to the first if statement?

bmm6o
  • 6,187
  • 3
  • 28
  • 55