Create a short program that uses list_of_days to store a list of the seven days of the week. Ask the user to choose a day of the week by picking a number from 1-7. Print the day in the index position with that number. Use conditionals to display which days are weekdays and which are weekend days.
Question
Create a short program that uses list_of_days to store a list of the seven days of the week. Ask the user to choose a day of the week by picking a number from 1-7. Print the day in the index position with that number. Use conditionals to display which days are weekdays and which are weekend days.
Solution
Sure, here is a simple Python program that fulfills your requirements:
# Create a list of the seven days of the week
list_of_days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
# Ask the user to choose a day of the week by picking a number from 1-7
day_number = int(input("Choose a day of the week by picking a number from 1-7: ")) - 1
# Print the day in the index position with that number
chosen_day = list_of_days[day_number]
print("You have chosen: " + chosen_day)
# Use conditionals to display which days are weekdays and which are weekend days
if chosen_day in ['Saturday', 'Sunday']:
print(chosen_day + " is a weekend day.")
else:
print(chosen_day + " is a weekday.")
This program first creates a list of the days of the week. It then asks the user to input a number from 1-7. The program subtracts 1 from this number to get the correct index in the list (since Python list indices start at 0). It then prints the chosen day and checks whether it is a weekday or a weekend day.
Similar Questions
Write a function 'returnDay' that takes one parameter(number from 1 to 7) and returns the day of the week.(where 1 is Monday, 2 is Tuesday, 3 is Wednesday, etc).If the number is less than 1 or greater than 7, the function should return null.Note: Store the days of the week in the array.
There are 7 days in a week.Let x represent the number of weeks and y represent the corresponding number of days.Use the equation y=7x to find the value of y when x=1.y=
Solution.java:23: error: ')' expected System.out.printf("The day of the week is -> %s %n%n%n", "daysOfWeek[dayOfWeek]"; ^
Given day of the week encoded as 0 = Sun, 1 = Mon, 2 = Tue, ... 6 = Sat, and a boolean vacation indicating if we are on vacation. Write the function alarm_clock(day, vacation) that returns a string of the form "7:00" indicating when the alarm clock should ring. On weekdays (Mon-Fri), the alarm should be "7:00" and on the weekend (Sat and Sun) it should be "10:00". However, if we are on vacation, then on weekdays it should be "10:00" and weekends it should be "off".Examplesalarm_clock(3, False) -> "7:00"alarm_clock(5, True) -> "10:00"alarm_clock(6, True) -> "off"
import java.util.Calendar;public class JavaDateAndTimeDaysOfWeekFinder { public static String findDay(int month, int day, int year) { System.out.println("_________________________ Java Date And Time Days Of Week Finder _________________________________"); System.out.printf("The day of the week is -> %d/%d/%d %n",day,month,year); Calendar calendar = Calendar.getInstance(); calendar.set(year, month-1, day); // note: months in Calendar are 0-based (0 = January, 1 = February, ..., 11=December) int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); String[] daysOfWeek = {"", "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY" }; System.out.printf("The day of the week is -> %s %n%n%n", "daysOfWeek[dayOfWeek]"; return daysOfWeek[dayOfWeek]; }}
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.