- 简述编译型与解释型语言的区别,且分别列出你知道的哪些语言属于编译型,哪些属于解释
- 执行 Python 脚本的两种方式是什么
- 直接调用python脚本
- 调用python解释器来调用python脚本
- Pyhton 单行注释和多行注释分别用什么?
- 单行注释:#
- 多好注释:''' '''
- 布尔值分别有什么?
- True和False
- 声明变量注意事项有那些?
- 变量名只能是字母、数字或下划线的任意组合;
- 变量名的第一个字符不能是数字;
- 关键字不能声明为变量 :['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']
- 如何查看变量在内存中的地址?
- username = 'Egon'
- id(username)
- 写代码
- 实现用户输入用户名和密码,当用户名为 seven 且 密码为 123 时,显示登陆成功,否则登陆失败!
-
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!')
- 实现用户输入用户名和密码,当用户名为 seven 且 密码为 123 时,显示登陆成功,否则登陆失败,失败时允许重复输入三次
-
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
-
-
- 实现用户输入用户名和密码,当用户名为 seven 或 alex 且 密码为 123 时,显示登陆成功,否则登陆失败,失败时允许重复输入三次
-
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
-
-
写代码
a. 使用while循环实现输出2-3+4-5+6...+100 的和-
#!/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)
-
-
b. 使用 while 循环实现输出 1,2,3,4,5, 7,8,9, 11,12 使用 while 循环实现输出 1-100 内的所有奇数
-
#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
#使用 while 循环实现输出 1-100 内的所有奇数 count = 1 while count <= 100: if count%2 != 0 : print('count is: ',count) count += 1
-
-
e. 使用 while 循环实现输出 1-100 内的所有偶数
-
#使用 while 循环实现输出 1-100 内的所有偶数 count = 1 while count <= 100: if count%2 == 0 : print('count is: ',count) count += 1
-
- 实现用户输入用户名和密码,当用户名为 seven 且 密码为 123 时,显示登陆成功,否则登陆失败!
-
现有如下两个变量,请简述 n1 和 n2 是什么关系?
-
n1 = 123456 n2 = n1
- id(n1) = 2758374506224 id(n2) = 2758374506224 使用了同一个内存空间
-