• python基础,python第一课


    学习python的第一天,总结和记录我的学习过程

    python发展及介绍

    1994年V1.0

    2000年V2.0,目前最高版本2.7

    2008年V3.0 ,3.0不兼容之前版本

    安装python环境

    python下载地址:https://www.python.org/downloads/

    windows 安装python,python3.0

    配置环境变量

    安装IDE

    pycharm,目前最流行pythonIDE 工具

    打印hello world

    1 #! /usr/bin/env python
    2 #-*- coding:utf-8 -*-
    3 
    4 print("Hello World")

    变量

    变量起名有意义,建议使用下划线分割:old_man

    字符编码

    ascII 美国使用,编码默认使用,编程时默认保存utf-8,读写也是utf-8

    GB2312支持7000+字符,在手机,设备中使用

    GBK 1830 在PC使用

    UTF-8,ascii码占1个字节、欧洲字符占2个字节,东亚的字符占3个字节

    用户交互,输入

    1 #!/usr/bin/env python
    2 # -*- coding: utf-8 -*-
    3 
    4 name = input("请输入你的名字")
    5 print("my name is ",name)

    输入密码不可见,使用getpass模块的getpass方法

    1 #!/usr/bin/env python
    2 # -*- coding: utf-8 -*-
    3 
    4 import getpass
    5 
    6 username = input("username:")
    7 password = getpass.getpass("password:")

    if else 判断和循环

    if和while的使用

     1 #! /usr/bin/env python
     2 #-*- coding:utf-8 -*-
     3 
     4 old_boy = 56
     5 count = 0
     6 while count < 3:
     7     guess_age = int(input("guess_age:"))
     8     if guess_age == old_boy:
     9         print("your are same!")
    10         break
    11     elif guess_age < old_boy:
    12         print("your are to young!")
    13     else:
    14         print("you are older")
    15     count += 1
    16     if count == 3:
    17         countine_confirm = input("your have guessing?")
    18         if countine_confirm != 'n':
    19             count = 0

     for 循环

    1 for i in range(10):
    2     print("---------------",i)
    3     for j in range(0,10,1):
    4         print(j)

     作业

    1、使用while循环输入 1 2 3 4 5 6     8 9 10
    1 i = 1
    2 Sum =0
    3 while i < 101:
    4     Sum = Sum + i
    5     i += 1
    6 print("1+2+3+4+5+...100=%s"%Sum)
    View Code
    2、求1-100的所有数的和
    i = 1
    Sum =0
    while i < 101:
        Sum = Sum + i
        i += 1
    print("1+2+3+4+5+...100=%s"%Sum)
    View Code
    3、输出 1-100 内的所有奇数
    i = 1
    while i < 101:
        if i % 2 == 1:
            print(i)
        i += 1
    View Code
    4、输出 1-100 内的所有偶数
    i = 0
    while i < 101:
        if i % 2 == 0:
            print(i)
        i += 1
    View Code
    5、求1-2+3-4+5 ... 99的所有数的和
    i = 1
    Sum = 0
    while i < 100:
        if Sum % 2 == 1:
            Sum = Sum + i
        if Sum % 2 == 0:
            Sum = Sum - i
        i += 1
    print("1-2+3-4+5-6...99=%s" % Sum)
    View Code
    6、用户登陆(三次机会重试)
    username = "abc"
    password = "123"
    i = 1
    flag = True
    while i <= 3:
        _username = input("请输入用户名:")
        if _username == username:
            while flag:
                _password = input("请输入密码:")
                if _password == password:
                    exit("登录成功,退出")
                else:
                    print("密码错误,请重新输入")
                    continue
        else:
            print("输入账号错误请重新输入:")
            i += 1
            continue
        i += 1
    View Code
  • 相关阅读:
    JQuery Basic Features Quick Walkthrough
    JavaScrip基础讲座
    玩玩反射
    Js Pattern
    Js Pattern
    Caching in ASP.NET MVC
    JQuery Plugin 2
    centos 开启关闭网卡
    mysql服务设置远程连接 解决1251 client does not support ..问题
    报错 "Host '192.168.209.1' is not allowed to connect to this MySQL server"
  • 原文地址:https://www.cnblogs.com/Ksen/p/Ksen.html
Copyright © 2020-2023  润新知