This is the 18th day of my participation in Gwen Challenge

Examples of 31

The title

Enter the first letter of the week to determine the day of the week. If the first letter is the same, proceed to the second letter.

Analysis of the

It is better to use the switch statement. If the first letter is the same, use the switch statement or if statement to judge the second letter.

code

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# @version : 1.0
# @Time : 2021/4/10 10:35
# @Author : cunyu
# @Email : [email protected]
# @Site : https://cunyu1943.site
# official account: Village Yuyao
# @File : 31.py
# @Software: PyCharm
# @desc: Exercise example 31

if __name__ == '__main__':

    letter = input(Enter the day of the week:)

    if letter == 'S':
        print('Continue with the second letter :')
        letter = input("Please enter :")
        if letter == 'a':
            print('Saturday: Saturday')
        elif letter == 'u':
            print('Sunday: Sunday')
        else:
            print('Input error')

    elif letter == 'F':
        print('Friday: Friday')

    elif letter == 'M':
        print('Monday: Monday')

    elif letter == 'T':
        print('Continue with the second letter :')
        letter = input("Please enter :")

        if letter == 'u':
            print('Tuesday: Tuesday')
        elif letter == 'h':
            print('Thursday: Thursday')
        else:
            print('Input error')

    elif letter == 'W':
        print('Wednesday: Wednesday')
    else:
        print('Input error')

Copy the code

The results of

Examples of 32

The title

Print the values of the list in reverse order.

Analysis of the

Look at the manipulation of lists in Python.

code

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# @version : 1.0
# @Time : 2021/4/10 10:38
# @Author : cunyu
# @Email : [email protected]
# @Site : https://cunyu1943.site
# official account: Village Yuyao
# @File : 32.py
# @Software: PyCharm
# @desc: Exercise example 32

if __name__ == '__main__':
    lists = ['Java'.'C++'.'C'."Go"]
    for item in lists[::-1] :print(item, end='\t')

Copy the code

The results of

Examples of 33

The title

Separate lists by commas.

Analysis of the

Join using the join function.

code

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# @version : 1.0
# @Time : 2021/4/10 10:40
# @Author : cunyu
# @Email : [email protected]
# @Site : https://cunyu1943.site
# official account: Village Yuyao
# @File : 33.py
# @Software: PyCharm
# @desc: Exercise example 33

if __name__ == '__main__':
    lists = [1.3.4.5.6]

    for i in range(len(lists)):
        if i == len(lists) - 1:
            print(lists[i], end=' ')
        else:
            print(lists[i], end=', ')

Copy the code

The results of

Examples of 34

The title

Practice function calls.

Analysis of the

Use the function to print the string three times.

code

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# @version : 1.0
# @Time : 2021/4/10 10:59
# @Author : cunyu
# @Email : [email protected]
# @Site : https://cunyu1943.site
# official account: Village Yuyao
# @File : 34.py
# @Software: PyCharm
# @desc: Exercise example 34

def function(str) :
    print(str)


if __name__ == '__main__':
    str = input("Input string \n")
    for i in range(3):
        function(str)

Copy the code

The results of

Examples of 35

The title

Text color Settings.

Analysis of the

The character color of the terminal is controlled by the escape sequence. The common color parameters are as follows:

Display mode The effect The foreground The background color Color description
0 Terminal Default Settings 30 40 black
1 The highlighted 31 41 red
4 Use underscores 32 42 green
5 flashing 33 43 yellow
7 The white shows 34 44 blue
8 invisible 35 45 purple
22 Unhighlighted 36 46 Green, blue
24 To underline 37 47 white
25 To flash
27 Non counter white display
28 visible

code

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# @version : 1.0
# @Time : 2021/4/10 11:02
# @Author : cunyu
# @Email : [email protected]
# @Site : https://cunyu1943.site
# official account: Village Yuyao
# @File : 35.py
# @Software: PyCharm
# @desc: Exercise example 35

class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'


if __name__ == '__main__':
    print(bcolors.WARNING + "Warning color font?" + bcolors.ENDC)

Copy the code

The results of