People change jobs Self Python programming from the fourth day of hard to force ----------

2019-09-14  21:15:24

Today is the fourth day of learning Python, also write a blog on the fourth day

Today's content is related to 'list', 'tuple', 'range' usage

List: CRUD, nested list

Tuple: nested tuple

range: range of specific usage

Well, the daily record. Come on!

I ====== ====== ====== ====== is a fast ====== ====== ====== of music = ====== ====== partial cut lines =====

A important points 
1. list (CRUD)
listing can hold large amounts of data do not limit the type of data representation: [] brackets each of a comma-separated
list of strings and have the same index and. slice
common functions:
1. by: the append ()
2. delete: Remove ()
3. change: index modifier
4. check: for loop
common methods:
1. len ()
2. COUNT ()
3. Sort () Sort

2. list nested
dimensionality reduction operation

3. tuple tuple
when only one element is a tuple to use a comma, or tuples not
immutable list of read-only list. there indexing and slicing.
immutable that the internal ... If the sub-elements are child elements of the list elements in the list can be changed to

4. range ()
count
has one parameter: the end until the
two parameters: 1. the start position, end position 2. the
three parameters: 1 The starting position, end position 2. 3. step

Second error summary
1.continue role
# 11 write code: Calculated + 1-2 + 3 ... 88, 99 in addition to the sum of all the numbers?
COUNT. 1 =
SUM = 0
the while COUNT <100:
IF COUNT == 88:
COUNT = COUNT + 1
the Continue # - >> here forget to add the Continue
elif COUNT% 2 == 0:
sum- = COUNT
the else:
SUM + COUNT =
COUNT + 1 =
Print (SUM)
# emerge reasons for this error is not considered to continue the role of the
solution: You remember Qiaowan Code filtered again to see if there are missing or how, remember to consider the role of continue and break

position 2.print stood
# 9. calculate the content of user input there are several integer (to single digits in units).
Such as: content = input ( "Please enter the text:") as fhdal234slfh98769fjdla #
content = input ( "Please enter the content:")
COUNT = 0
for c in Content:
if c.isdigit ():
COUNT = 1 +
Print (COUNT) # - >> Print should be in the nest for years, if not in the and if the same level of nesting in
# recent position there always print placement error
solution: print to see what is to be output, the output is what to put there

tips: simplification of complex issues, complicate the simple question
== I was ==== ====== ====== === ====== ====== fast music ====== ====== of a ====== === partial cut line ======
# 10.写代码完成下列需求:
#     用户可持续输入(用while循环),用户使用的情况:
#     输入A,则显示走大路回家,然后在让用户进一步选择:
#         是选择公交车,还是步行?
#         选择公交车,显示10分钟到家,并退出整个程序。
#         选择步行,显示20分钟到家,并退出整个程序。
#     输入B,则显示走小路回家,并退出整个程序。
#     输入C,则显示绕道回家,然后在让用户进一步选择:
#         是选择游戏厅玩会,还是网吧?
#         选择游戏厅,则显示‘一个半小时到家,爸爸在家,拿棍等你。'并让其
#     重新输入A,B,C选项。:
#         选择网吧,则显示‘两个小时到家,妈妈已做好了战斗准备。'并让其重
#     新输入A, B,C选项。
while 1:
    lu = input('请选择ABC三个其中一个:').strip().upper()
    if lu=='A':
        s=input('你是要选择坐公交车还是步行:')
        if s=='坐公交车':
            print('十分钟到家')
        else:
            print('半个小时到家')
        break
    elif lu=='B':
        print('走小路回家')
        break
    elif lu=='C':
        s=input('你是要去游戏厅还是网吧')
        if s=='游戏厅':
            print('一个半小时到家,爸爸在家,拿棍等你')
        else:
            print('两个小时到家,妈妈已做好了战斗准备')
            continue
    else:
        print('没有这个选项')

#这个代码没难度,只是要写比较多.第一次写代码没出现错误,有点开心

 

Guess you like

Origin www.cnblogs.com/hpcz190911/p/11520338.html