Write a program that asks the user for a positive integer between 1 and 7 (Assume that the user may enter any number from 1 to 7 both inclusive) and prints the day of week corresponding to that number. Assume that the day of the week starts from MONDAY.
Now I have that assigment but not sure I understand it. Can someone explain me,I am new in Python!


We can start with a list of days of the week…

days_of_week = ['', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

Since we are starting on Monday as being day 1, I’ve inserted an empty string in index[0] position.

from random import randint

print days_of_week[randint(1, 7)]


if the user enters 1, you need to print MONDAY
if the user enter 2, you need to print TUESDAY

and so on, its a straight forward program


Cool I have done that. But input is my main problem.


Is raw_input not working?

day_number = raw_input("Enter 1 to 7 to indicate day of week")


Well that input line is my problem.


Aaaaa darn forgot that randint! I will try this and get back at you


I only used that as an example. Be sure to follow the instructions.


print week

I am using Python 2…I am that dumb or tired but something is wrong!


We cannot use the same variable for the list that we use for input else it wipes out the list.


than how to call back to list for input?


you need to ask for input, then use this input to get a value from the list

currently, you just overwrote the variable containing the list.

days_of_week = ['', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

day_number = raw_input("Enter 1 to 7 to indicate day of week")

print days_of_week[day_number]


Traceback (most recent call last):
File “C:/Users/Vedad/Desktop/”, line 6, in
TypeError: ‘list’ object is not callable


day_number=raw_input(‘Enter number to get day ‘)
day_of_week=[’’, ‘Monday’, ‘Tuesday’, ‘Wednesday’, ‘Thursday’, ‘Friday’, ‘Saturday’, ‘Sunday’]
print day_of_week(day_number)

like this? I get Error in this!


Got it didn’t put int() in input so it looked like str…Thanks to all,best community ever!!!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.