上課次日(實際上是第三天)

 

例:密碼必須有大寫字母,小寫字母,數字數組

password =____________        #__裏面能夠用input(),也能夠自定義輸入dom

A='ABCD.....'3d

B='abcd.......'code

C='1234.......'blog

count_1,count_2,count_3=False,False,False    #給參數賦值排序

for i in password:input

     if i in A:it

        count_1=Truefor循環

     if i in B:import

        count_2=True

     if i in C:

        count_3=True

if count_1 and count_2 and count_3:

   print('OK')

else:

    print('密碼必須有大寫字母,小寫字母,數字')

--------------------------------------------------------------------------------------------------------------------

例:計算器

num1,num2=map(float,input('Num1,Num2:>>').split(',')) #同時輸入2個數字
c=input('Choose Method : [+,-,-*,/]:>>')

if c in ' +,-,-*,/ ' :
 
if c == ' + ' :
print('OK')
print(' %f + %f = %f ' %(num1,num2,num1+num2))
elif c == ' - ' :

print(' %f - %f = %f ' %(num1,num2,num1-num2))

elif c == ' * ' :

print(' %f * %f = %f ' %(num1,num2,num1*num2))

elif c == ' / ' :

print(' %f / %f = %f ' %(num1,num2,num1/num2))

else:

#拋出異常

raise KeyError (' Only choose [ +,-,*,/ ] ')

---------------------------------------------------------------------------------------------------------------

例:隨機輸出

#######這是用VS code

import random

res = random.choice( [ '石頭' , ' 剪刀 ', ' 布 ' ] )

print(res)

 ########這是用Jupyter

----------------------------------------------------------------------------------------------------------------

 銀行輸密碼(3次)---------用for循環

password='151213'
mm=int(input('輸密碼(3次機會:)'))
for i in range(2):
if mm == password:
print('正確')
break
else:
print('錯誤',i+1,'次')
mm=int(input('輸密碼:(3次機會:)'))
else:
print('帳號鎖定')

--------------------------------------------------------------------------------------------------------------------

數組中隨機輸出:

import random
res=[ 'A' , ' B', ' 1 ', ' 2 ' ]
random.shuffle(res )

print(res)

--------------------------------------------------------------------------------------------------------------------------------------------------------

排序

a=[2,1,3]
a.sort()
print(a)

---------------------------------------------------------------------------------------------------------------------------------------------------------

昨天的例題:

a=int(input('Enter today’s day: '))
b=int(input('Enter the number of days elapsed since today: '))
week=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']

wl=(a+b)%7

print("Today is %s and the future day is %s"%(week[a],week[wl]))

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

a,b=map(int,input('輸入年份及月份 ').split(','))
if (a%4==0 and a%100!=0) or (a%400==0):
e=int( '29')
else:
e=int( '28')

if b==1 or b==3 or b==5 or b==7 or b==8 or b==10 or b==12 :
t=int( '31')
elif b==4 or b==6or b==9 or b==11:
t=int( '30')
else:
t==e

print('%d 年 %d 月份有 %d 天' %(a,b,t))

-------------------------------------------------------------------------------------------------------------------------------------

########昨天寫死了,今天要補死了,啊啊啊啊啊

相關文章
相關標籤/搜索