zoukankan      html  css  js  c++  java
  • python学习笔记 2019.5.5

    一、占位符的使用

    重点:

    1.%s是字符串占位符 ;%d%i是数字占位符 ;%f 是浮点数占位符

    2.变量名.isdigit 判断变量名是否看起来像数字, 返回值是 ture 或者 false

    3.type(变量名),查看变量的类型

     1 decide = 1
     2 
     3 while decide == 1:
     4     name = input("name:")
     5     age = input("age:")
     6     sex = input("sex:")
     7     salary = input("salary:")
     8     if age.isdigit() and salary.isdigit():
     9         decide = 0
    10     else:
    11         print()
    12         print("age and salary must input number,please resume input")
    13         print()
    14 
    15 # c = 10
    16 # b = type(age)
    17 # print(c)
    18 # print(b)
    19 
    20 age = int(age)
    21 salary = int(salary)
    22 
    23 form = '''
    24 ------info of %s------
    25 name = %s
    26 age = %d
    27 sex = %s
    28 salary = %i
    29 ------END------
    30 ''' %(name,name,age,sex,salary)
    31 
    32 print(form)
    View Code

    二、for循环

    1.for i in range(3).  #循环3次,其中"i"是变量,“()”的值是“0,1,2”

    2.for i in range(3,8). #循环5次,其中"i"是变量,“()”的值是“3,4,5,6,7”

    3.for i in range(3,100,2). #其中“2”是步长,“()”的值是“3,5,7,...,99”

    4. for : else:和while : else: 一样 。如果没有被break打断,就执行else语句。

    5.连续跳出两层循环,用标记位 (设置一个初始变量,在第一层循环跳出前对此变量重新赋值,在第二层变量做判断此变量如果为新的赋值就继续跳出第二层变量)

     1 #打印1-100,其中50-70不打印
     2 
     3 for number in range(1,101):
     4     if 50 <= number <= 70:
     5         continue
     6     print(number)
     7 
     8 #用户输入账号密码,最多出入3此
     9 
    10 account_right = "kentee"
    11 password_right = "123456"
    12 
    13 for time in range(3):
    14     account_input = input("please input your account:")
    15     password_input = input("please input your password:")
    16     if account_input == account_right and password_input == password_right:
    17         print("welcome to your python world!!!")
    18         break
    19     print("input the wrong",time+1,"time!")
    20 else:
    21     print("you have input thr wrong for 3 times.")
    View Code
  • 相关阅读:
    安装curl依赖库后yum不能使用问题解决
    leetcode Container With Most Water
    leetcode Median of Two Sorted Arrays
    leetcode Add Two Numbers(对指针的一些基本操作)
    hdu 4427 DP
    hdu 4454 三分*****
    HDU5917 RAMSEY定理
    UVAlive7501 Business Cycle 2015ECfinal B(二分模板)
    已知圆半径和外接正多边形边数求边长
    hdu4799 树型DP
  • 原文地址:https://www.cnblogs.com/kentee/p/10812128.html
Copyright © 2011-2022 走看看