PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 15, 2022

[FIXED] How to write a program to print name of day corresponding to the day number given by user

 September 15, 2022     list, printing, python, user-input     No comments   

Issue

I want an input like If I type 1 then it will give output Sunday , if I type 2 it will give Monday. I tried this code but it is not working , plz help

days =["Sunday" ,"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]

user_input = int(input("Enter Day"))
if user_input == (1,2,3,4,5,6,7) :
    print (days[0,1,2,3,4,5,6])

I want to make my program simple , I am a beginner


Solution

days =["Sunday" ,"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]

user_input = int(input("Enter Day (from 1-7)"))
if user_input:
    print (days[user_input-1])
else:
    print ("Your input is not valid")

With a dictionary

days_dict ={'1':"Sunday" ,'2':"Monday",'3':"Tuesday", '4':"Wednesday", '5':"Thursday", '6':"Friday", '7':"Saturday"}
print (days_dict[input("Enter Day (from 1-7): ")])


Answered By - Seyi Daniel
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing