List?


#1

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!


#2

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)]

#3

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


#4

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


#5

Is raw_input not working?

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

#6

Well that input line is my problem.


#7

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


#8

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


#9

week=[’’,‘MONDAY’,‘TUESDAY’,‘WENSDAY’,‘THURSDAY’,‘FRIDAY’,‘SATURDAY’,‘SUNDAY’]
week=raw_input()
print week

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


#10

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


#11

than how to call back to list for input?


#12

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.


#13
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]

#14

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


#15

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!


#16

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


#17

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