day6 流程控制 while循環 運算符
具體知識戳這裏
運算符
#算數運算符
# x=10
# y=3
#
# print(x / y) 除
# print(x // y) 除取整數
#
# print(x % y) #取余
# print(y**3) 求y的三次方
#了解部分
#字符串+,*
#列表:+,*
# l1=[1,2,3]
# l2=[4,5]
#
# print(l1+l2)
# print(l1*3) 輸出3個l1
#比較運算符
# num1=3
# num2=1
# print(num1 > num2)
# print(num1 < num2)
# print(num1 >= num2)
# print(num1 <= num2)
# print(num1 == num2)
# print(num1 != num2)
#==判斷的是值
#is判斷的是id
‘‘‘
>>> num1=1234567890123456789
>>> num2=1234567890123456789
>>>
>>>
>>> id(num1),type(num1),num1
(41798792, <class ‘int‘>, 1234567890123456789)
>>> id(num2),type(num2),num2
(41798832, <class ‘int‘>, 1234567890123456789)
>>>
>>>
>>> num1 == num2
True
>>> num1 is num2
False
‘‘‘
#其他類型的比較,註意:只能在同種類型之間進行比較(了解)
#字符串的比較是按照字符的位置依次比較
# s1=‘abc‘
# s2=‘abC‘
#
# print(s1 > s2)
# l1=[‘abc‘,2,‘a‘,‘b‘]
# l2=[‘abd‘]
# print(l1 > l2)
# print(l2 > l1)
#賦值運算
# x=10
# # x=x+1
# x+=1
# print(x)
#
# x/=3 #x=x/3
# print(x)
# x=10
# x%=3 #x=x%3
# print(x)
#邏輯與and
# age=input(‘您芳齡幾何>>: ‘)
# age=int(age)
# age=int(input(‘您芳齡幾何>>: ‘))
# sex=input(‘您的性別是>>: ‘)
#
# print(age > 50 and sex == ‘female‘)
#邏輯或or
# age=int(input(‘您芳齡幾何>>: ‘))
# sex=input(‘您的性別是>>: ‘)
#
# print(sex == ‘female‘ or age > 50 )
# print(False and True or True)
# print((False and True) or True)
# print(False and (True or True))
# #
#
# print(False or False and True)
# print(False or (False and True))
# print(False or True and True)
#
#
print(False or True and False or True)
print(False or ((True and False) or True))
# print(1 > 10 or ( (2 > 1 and 1 < -1) or 4 > 3))
# print(False or True)
流程控制
# if 條件:
# 子代碼1
# 子代碼2
# 子代碼3
# if True:
# print(‘ok‘)
# print(‘=====?>‘)
# print(‘=====?>‘)
# print(‘=====?>‘)
# print(‘=====?>‘)
# print(‘=====?>‘)
# age=int(input(‘您芳齡幾何>>: ‘))
# sex=input(‘您的性別是>>: ‘)
#
# if sex == ‘female‘ or age > 50:
# print(‘alex很中意你,我們結婚吧‘)
# else:
# print(‘不是我的菜‘)
# OLDBOY_AGE=56
# age=input(‘猜一猜年齡>>: ‘)
# age=int(age)
#
# if age > OLDBOY_AGE:
# print(‘太大了‘)
# elif age < OLDBOY_AGE:
# print(‘太小了‘)
# else:
# print(‘猜對了‘)
‘‘‘
90及以上 : A
80分以上90以下 : B
70分以上80以下 : C
60分以上70以下 : D
60以下 : E
‘‘‘
# score=input(‘>>: ‘)
# score=int(score)
#
# if score >= 90:
# print(‘A‘)
# elif score >=80 and score <90:
# print(‘B‘)
# elif score >=70 and score <80:
# print(‘C‘)
# elif score >=60 and score < 70:
# print(‘D‘)
# else:
# print(‘E‘)
score=input(‘>>: ‘)
score=int(score)
if score >= 90:
print(‘A‘)
elif score >=80:
print(‘B‘)
elif score >=70:
print(‘C‘)
elif score >=60:
print(‘D‘)
else:
print(‘E‘)
print(‘====>‘)
while循環
# while 條件:
# 循環體的代碼1
# 循環體的代碼2
# 循環體的代碼3
# count=0
# while count < 10:
# print(count)
# count+=1
# while True: #死循環
# print(‘ok‘)
# while 1: #死循環
# print(‘ok‘)
#break:跳出本層循環
# count=0
# while count < 10:
# if count == 5:
# break
# print(count)
# count+=1
#continue:跳出本次循環
#0 1 2 3 7 8 9
# count=0
# while count < 10:
# if count >=4 and count <=6:
# count += 1
# continue
# print(count)
# count+=1
# OLDBOY_AGE=56
# while 1:
# age=input(‘猜一猜年齡>>: ‘)
# age=int(age)
#
# if age > OLDBOY_AGE:
# print(‘太大了‘)
# elif age < OLDBOY_AGE:
# print(‘太小了‘)
# else:
# print(‘猜對了‘)
# break
# OLDBOY_AGE=56
# count=1
# while count <= 3:
# age=input(‘猜一猜年齡>>: ‘)
# age=int(age)
#
# if age > OLDBOY_AGE:
# print(‘太大了‘)
# count+=1
# elif age < OLDBOY_AGE:
# print(‘太小了‘)
# count+=1
# else:
# print(‘猜對了‘)
# break
OLDBOY_AGE=56
count=1
while True:
if count > 3:
print(‘您猜的次數超過限制‘)
break
age=input(‘猜一猜年齡>>: ‘)
age=int(age)
if age > OLDBOY_AGE:
print(‘太大了‘)
elif age < OLDBOY_AGE:
print(‘太小了‘)
else:
print(‘猜對了‘)
break
count += 1
# OLDBOY_AGE=56
# while True:
# score = input(‘>>: ‘)
# score = int(score)
#
# if score >= 90:
# print(‘A‘)
# if score >= 80:
# print(‘B‘)
# if score >= 70:
# print(‘C‘)
# if score >= 60:
# print(‘D‘)
# if score < 60:
# print(‘E‘)
OLDBOY_AGE=56
count=0
while True:
if count > 2:
break
age=input(‘猜一猜年齡>>: ‘)
age=int(age)
if age > OLDBOY_AGE:
print(‘太大了‘)
if age < OLDBOY_AGE:
print(‘太小了‘)
if age == OLDBOY_AGE:
print(‘猜對了‘)
break
count += 1
day6 流程控制 while循環 運算符