No.1

作者: ledwin89 | 来源:发表于2017-02-12 16:58 被阅读0次

    第一个PYTHON程序——入派仪式!


    作为经典的语言学习起手式,你绝不能错过这样的一个小程序。

    print("Hello World!")

    写下你的第一行PYTHON代码,执行后给你的回答。

    Hello World!

    你已经入坑了!

    变量——给你个简单的定义


    变量是为了存储信息,在程序中被调用,标识数据名称或类型。

    变量定义的规则:

    变量名只能是字母,数字或下划线的任意组合

    变量名的第一个字符不能是数字

    关键字不能生命为变量

    为了方便读取等,变量命名一般都遵循变量本身的意义,如名字命名为name,年龄为age等等。

    name = "Laay"  #字符串类型string

    age = "21"  #int类型

    province = "shandong"

    NameOfTwinsGf = "hanmeimei"

    name_of_twins_gf = "hanmeimei"

    address = “shanghai”

    address1 = address

    address = “beijing”   #address1 赋的是值,而不是变量,所以不变

    注释


    #       最多不超过80个字符

    ’‘’ ‘’‘   多行注释

    格式化字符串


    name = input("input your name:")

    age =int( input("input your age:"))

    job = input("input your job:")

    print("name is :",name)

    print("age is :",age)

    print("job is :",job)

    msg = '''

    infomation of user %s:

    -----------------------------

    name:  %s

    age   :  %d 

    job    :   %s

    -----------------------------

    ''' % (name,name,age,job)

    print(msg)

    if 判断


    _username = ‘Laay’

    _password = ‘Laay’

    username = input('input your name :')

    password = input('input your password:')

    if _username == username and _password == password:

        print('login..')

    else:

        print('username or password is correct...')

    age = 22

    guess_num = int(input('input your num:'))

    if guess_num == age :

        print('congratulations! you got it.')

    elif guess_num >age:

        print('think smaller!')

    else:

        print('think bigger!')

    循环


    age = 22

    counter = 0

    for i in range(10)

        if counter<3:

            guess_num = int(input('input your num:'))

            if guess_num == age :

                print('congratulations! you got it.')

                break

            elif guess_num >age:       

                print('think smaller!')

            else:

               print('think bigger!')

        else:

            continue_confirm = input('Do you want to contnue because you are stupid:')

            if countinue_confirm == 'y'

                counter   =  0

                ciontinue

            else:

                print('bye')

                break

        count + = 1

    相关文章

      网友评论

          本文标题:No.1

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