1、条件表达式
num1=int(input('num1='))
num2=int(input('num2='))
print(str(num1)+'>='+str(num2) if num1>=num2 else str(num1)+'<='+str(num2))
2、pass语句
s=input('您是会员吗:Y/N')
if s=='Y':
pass
else:
pass
3、布尔值
age=int(input('您的年龄是:'))
if age:
print(age)
else:
print('年龄是',age)
4、range()
s1=range(12)
print(list(s1))
s2=range(12,44)
print(list(s2))
s3=range(12,44,2)
print(list(s3))
num=int(input('请输入要判断的数值:'))
print('num在数列1中',num in s1)
print('num在数列2中',num in s2)
print('num在数列3中',num in s3)
5、while
num=1
while num<=10:
print(num)
num+=1
num1=int(input('请输入起始数:'))
num2=int(input('请输入终止数:'))
sum=0
while num1<=num2:
sum+=num1
num1+=1
print('sum=',sum)
#1~100的偶数和
sum1=0
num=1
while num<=100:
if num%2==0:#if not bool(num%2):
sum1+=num
else:
sum1=sum1
num+=1
print('sum1=',sum1)
#1~100的奇数和
sum2=0
num=1
while num<=100:
if num%2:
sum2+=num
else:
sum2=sum2
num+=1
print('sum2=',sum2)
6、for-in循环
for i in range(100):
print(i)
for _ in range(100):
print('hello')
sum=0
for i in range(1,101):
if i%2==0:
sum += i
print(sum)以下
#输出100-999之间的水仙花数,例如153=3*3*3+5*5*5+1*1*1
for i in range(100,1000):
g=i%10
s=i//10%10
b=i//100
if i==g**3+s**3+b**3:
print(i)
7、break
for s in range(3):
psw=input('请输入密码:')
if psw=='123456':
print('密码正确')
break
else:
print('密码错误')
i=0
while i<3:
psw = input('请输入密码')
if psw=='123456':
print('密码正确')
break
else:
print('密码错误')
i+=1
8、continue
#1-50之间所有5的倍数
#1-50之间所有5的倍数
for i in range(1,51):
if(i%5!=0):
continue
print(i)
标签:int,num1,Python,day6,range,num,print,input
From: https://blog.51cto.com/u_16080683/7435710