日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Python示例程序

系統 1720 0

Recursive articles(遞歸篇)

Feibo sequence

            
              def fib(number):
    if number==0 or number == 1:
        return number

    else:
        return fib(number-1) + fib(number-2)

for i in range(8):
    print("fib(%2d) = %2d" % (i,fib(i)))
            
          

We can control the time of the function.

            
              def fib(number):
    if number==0 or number == 1:
        return number

    else:
        return fib(number-1) + fib(number-2)
while True:
    a = int(input("How many do you want?"
                  "\nThis integer must be > 0"
                  "Please enter your integer:"))
    if a < 0:
        print("The integer of you enter is wrong,please enter again!\n")
        continue
    for i in range(a+1):
        print("fib(%d) = %2d" % (i,fib(i)))
    print()
            
          

List's using methods.

            
              # creating an empty list
list = []

# add new value to the list
for number in range(1,11):
    list += [ number ]

print(list)
print()
# len(list) is the method to get the length of the list
print("There are",len(list),"elements in the list")
print()

# print the values in list
i = 0
for item in list:

    print("list[%d] is %d"%(i,item))
    i += 1
print()

# change the value in list
list[0] = 100
# if the index lower than 0
# it will Count from the right
# this is a logical error that is not serious
# better never use it!!!!!
list[-3] = 999
print(list)
            
          

Dictionary

            
              # creating empty dictionary
empty_dictionary={"name":"No"}

# creating another dictionary
grade={"name":"Sabo",
       "grade":"Good!",
       }

# output the grade
print("grade dictionary is")
print(grade)
print()

# add to our empty dictionary
print("before add grade")
print("empty_dictionary is ")
print(empty_dictionary)
print()

print("after add grade")
print("empty_dictionary is ")
empty_dictionary.update(grade)
print(empty_dictionary)
            
          

?


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 商南县| 绵竹市| 武夷山市| 渭南市| 彭泽县| 宜阳县| 镇宁| 泰州市| 枣阳市| 甘孜县| 徐闻县| 郧西县| 桐乡市| 灵武市| 合川市| 无锡市| 台中县| 岳阳县| 孟连| 会泽县| 博爱县| 波密县| 龙山县| 彭水| 威信县| 西城区| 怀远县| 呼玛县| 绵阳市| 邵阳市| 恩施市| 微山县| 平原县| 静乐县| 丰原市| 巫山县| 定南县| 伊金霍洛旗| 合作市| 临高县| 青田县|