[Python] Gets weekday strings

Principle: string sections

1.0 Code:

# Gets weekday strings 
weekStr = " Monday Tuesday Wednesday Thursday Friday Saturday Sunday " 
weekId = eval (the INPUT ( " Please enter the week numbers (1-7): " )) # get user input, remove the quotation marks around with eval function , so that a digital value entered into 
POS = (-weekId. 1). 3 * # calculation starting index position weekStr 
Print (weekStr [POS: + POS. 3]) # string sections

result:

 

2.0 code:

# Get String week 
weekStr = " MTWTFSS " 
weekId = eval (INPUT ( " Please enter the week number (1-7): " )) # get user input, the quotation marks on both sides by removing the eval function, let the input value into a digital 
Print ( " week " + weekStr [-weekId. 1]) # string connection

Guess you like

Origin www.cnblogs.com/HGNET/p/12114379.html