You are on page 1of 1

Write a program using IF statements that asks the user for an day of the week( between 1 and 7) 1 is for

Sunday and 7 is Saturday. If the user inputs a number outside the range of 1 to 7, the program prints "Day not in
range, please try again". If the user enters a character, the program should print "Use numbers only".

day = input('Enter a day of the week (1-7): ');

if ~isnumeric(day) || ischar(day) || isletter(day)% checks if what is entered is a number or no


disp('Use numbers only.');
elseif day < 1 || day > 7
disp('Day not in range, please try again.');
elseif day == 1
disp('Sunday');
elseif day ==2
disp('Monday');
elseif day == 3
disp('Tuesday');
elseif day == 4
disp('Wednesday');
elseif day == 5
disp('Thursday');
elseif day == 6
disp('Friday');
else
disp('Saturday');
end

Friday

You might also like