勤练基本功,才能上巅峰!!!
作业1练习:大部分题目都能熟练写出。第8题,对最后的else print 位置有些不是很理解(开始不加else,一直无法执行需要结果,加了else就对了)。第9、10有点不是很会。继续加油
#!/usr/bin/env/python
# -*- coding: UTF-8 -*-
'''
第1题:判断逻辑语句的true.false
3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2
运行顺序:
true and 2 or true and 3 and 4 or true
2 or 3 and 4 or true
2 or 4 or true
2
'''
'''
第2题:输出1-10数字
count =0
while count<10:
count +=1
print(count)
'''
'''
第3题:1-100数字求和
num =1
a =1
while num<100:
num =num+1
a +=num
print(a)
'''
'''
第4题,输出100以内奇数
i = 1
while i<=100:
if i%2 == 1:
print(i)
i +=2
'''
'''
第5题,输出100以内的偶数
i = 2
while i<101:
if i%2 == 0:
print(i)
i +=2
'''
'''
第6题:求和:1-2+3-4…+99
count = 1
sum = 0
while count <= 99:
if count%2 == 1:
sum += count
else:
sum = sum-count
print(sum)
'''
'''
第7题,用户登陆三次机会重试
(这题花了一些时间,
就是land_word这句放到while之前,
造成程序一直无暂停输出,思考一会执行顺序,就正确了!)
'''
UsrName= "Zhanshan"
pass_word = "A123456"
count = 0
while count<3:
land_word = input("你有3次机会,输入登录密码:")
if land_word == pass_word:
print("you get it. welcome…")
break
else:
a =2-count
print("密码错误,你还有",a,"次机会")"
count +=1
if land_word != pass_word:
print("you are fuck off!")
'''
第8题,用户输入一个数,判断是否是质数(升级版)
a = int(input("输入一个数字"))
b = 2
while b<= (a/2):
if a%b == 0:
print(a,"不是质数")
break
else:
pass
b +=1
else:
print(a,"是质数")
'''
'''
第9题,输入一个数,判断这是几位数(用算法实现)(升级版)
第10题,输入一段广告语,判断是否合法.判断合法的标准是:是否包含"第一"、"稀缺"、"国家级"等字样,如果包含,提示不合法.(升级版)
'''