Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to input a few letters in python to automatically determine what day it is?

Shulou Source: shulou.com Published: 2022-06-01 02:39:28 10月02日 Update

Xiaobian to share with you how python to enter a few letters can automatically judge the day of the week, I believe most people still do not know how to share this article for your reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

Question: Do you think it is possible to determine the day of the week by inputting a letter?

First of all, you can't, you need to enter at least 2 letters!

By judging sentences, automatic judgment can be realized.

Monday to Sunday English words are as follows: Monday Tuesday Wednesday Thursday Friday Saturday Sunday

Saturday and Sunday have the same initial letter, Tuesday and Thursday have the same initial letter, and you need to continue to judge the second letter to distinguish them

Program implementation idea: first accept the user input of the first letter and the first letter of the week to match if it is T or S, and then continue to let the user input the second letter input M, W, F, you can directly locate the use of the program Grammar>>if

>>elif

>>else

The procedure is as follows

First accept user input statements

letter = input("Please enter the first letter: ")

Then Saturday and Sunday are judged, requiring the user to enter the second letter.

if letter == 'S':

letter = input("Please enter the second letter: ")

if letter =='a':

print("Saturday")

elif letter == 'u':

print ('Sunday ')

else:

print ('input error')

Tuesday and Thursday are the same.

elif letter == 'T':

letter = input("Please enter the second letter: ")

if letter =='u':

print("Tuesday")

elif letter == 'h':

print ('Thursday ')

else:

print ('input error')

Friday, Monday and Wednesday

elif letter == 'F':

print("Friday")

elif letter=='M':

print ('Monday ')

elif letter=='W':

print ('Wednesday ')

else:

print ('input error')

In this way, the judgment of all days in a week is completed;

But here, at the end of the program, an else: print ('input error') is added to satisfy the condition that the user enters the first letter of a non-week. The logic of the program is perfect.

The above is "Python how to enter a few letters can automatically determine the day of the week" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Tags: Week input letter user program error article same content word sentence not much most days ideas more conditions knowledge industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Huawei macOS Docker OPPO Reno