美文网首页
2019-03-14 自学Python记录

2019-03-14 自学Python记录

作者: 墨先生_jin | 来源:发表于2019-03-14 21:26 被阅读0次

今天学习了Python第一章,但是很遗憾,我并没有学习完成这一章内容,现在把今天的学习内容写下:

嵌套和可变循环:

猜数小程序:

while guess != secret and tries < 6:

    guess = input("what's your guess?")

    if guess < secret:

        print"Too low,ye scurvy dog!"

    elif guess >secret:

        print "Too high,landlubber!"

    tries =tires+1

一次打印3个乘法表:

for M in range(5,8):

    for i in range(1,11):

        print i,"X",M,"=",i*M

    print

可变循环:

nM=int (raw_input('how many stars do you want?'))

for i in range (1,nM):

    print "*",

可变嵌套循环

numLines=int (raw_input('how many lines do you want?'))

numStars=int(raw_input('how many stars per lines?'))

for i in range (1,numLines):

    for i in range (1,numStars):

      print'*',

    print

利用双重嵌套循环生成星号块

numBlocks=int(raw_input('how many blocks do you want?'))

numLines=int(raw_input('how many lines do you want?'))

numStars=int(raw_input('how many stars do you want?'))

for i in range (1,numBlocks):

    for i in range (1,numLines):

        for i in range (1,numStars):

            print'*',

        print

    print

相关文章

网友评论

      本文标题:2019-03-14 自学Python记录

      本文链接:https://www.haomeiwen.com/subject/otlhmqtx.html