Python20-Day01

  1. 简述编译型与解释型语言的区别,且分别列出你知道的哪些语言属于编译型,哪些属于解释
    1. 编译型语言是一种以编译器来实现的编程语言,优缺点:执行速度快,调试麻烦
      1. 编译型语言:Java,Go,C,C++
    2. 解释性语言不要编译,相当于同声传译,优缺点:执行速度慢,调试方便
      1. 解释型语言:Python,PHP,Perl,JavaScript,Ruby
  2. 执行 Python 脚本的两种方式是什么
    1. 直接调用python脚本
    2. 调用python解释器来调用python脚本
  3. Pyhton 单行注释和多行注释分别用什么?
    1. 单行注释:#
    2. 多好注释:''' '''
  4. 布尔值分别有什么?
    1. True和False
  5. 声明变量注意事项有那些?
    1. 变量名只能是字母、数字或下划线的任意组合;
    2. 变量名的第一个字符不能是数字;
    3. 关键字不能声明为变量 :['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']
  6. 如何查看变量在内存中的地址?
    1. username = 'Egon'
    2. id(username)
  7. 写代码
    1. 实现用户输入用户名和密码,当用户名为 seven 且 密码为 123 时,显示登陆成功,否则登陆失败!
      1. while True:
            username = input('Please input your username: ')
            passwd = input('Please input your password: ')
            if username == 'seven' and passwd == '123':
                print('Login Successful!')
            else:
                print('Login Failed!')
      2. 实现用户输入用户名和密码,当用户名为 seven 且 密码为 123 时,显示登陆成功,否则登陆失败,失败时允许重复输入三次
        1. count = 1
          while count <=3:
              username = input('Please input your username: ')
              passwd = input('Please input your password: ')
              if username == 'seven' and passwd == '123':
                  print('Login Successful!')
              else:
                  print('Login Failed!')
              count+=1
    2. 实现用户输入用户名和密码,当用户名为 seven 或 alex 且 密码为 123 时,显示登陆成功,否则登陆失败,失败时允许重复输入三次
      1. count = 1
        user_name = ['seven','alex']
        while count <=3:
            username = input('Please input your username: ')
            passwd = input('Please input your password: ')
            if username in user_name and passwd == '123':
                print('Login Successful!')
            else:
                print('Login Failed!')
            count+=1
    3. 写代码
      a. 使用while循环实现输出2-3+4-5+6...+100 的和

      1. #!/usr/bin/env python
        # (((2-3)+4)-5)+6-7+8-9+10-11+12
        第一种:
        count = 2
        count_sum = 2
        while count <100:
            count+=1
            #if(i%2==0){sum-=i;}else{sum+=i;}
            if count%2 != 0:
                # count_sum-=count
                count_sum=count_sum-count
            else:
                # count_sum+=count
                count_sum=count_sum+count
        print('count_sum的和:',count_sum)
        
        
        第二种:
        (((2-3)+4)-5)+6-7+8-9+10-11+12
        count = 2
        count_sum = 2
        while count <100:
            count+=1
            if count%2 == 0:
                count_sum = count / 2 + 1
        print('count_sum的和:',count_sum)
    4. b. 使用 while 循环实现输出 1,2,3,4,5, 7,8,9, 11,12 使用 while 循环实现输出 1-100 内的所有奇数

      1. #1,2,3,4,5, 7,8,9, 11,12
        count = 1
        while count <= 12:
            if count != 6 and count != 10:
                print('count is: ',count)
            count += 1
        View Code
        #使用 while 循环实现输出 1-100 内的所有奇数
        count = 1
        while count <= 100:
            if count%2 != 0 :
                print('count is: ',count)
            count += 1
        View Code
    5. e. 使用 while 循环实现输出 1-100 内的所有偶数

      1. #使用 while 循环实现输出 1-100 内的所有偶数
        count = 1
        while count <= 100:
            if count%2 == 0 :
                print('count is: ',count)
            count += 1
  8. 现有如下两个变量,请简述 n1 和 n2 是什么关系?

    1.      n1 = 123456
            n2 = n1
    2. id(n1) = 2758374506224  id(n2) = 2758374506224  使用了同一个内存空间
 


原文地址:https://www.cnblogs.com/mrwang1101/p/7986970.html