Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report