The next day in class (in fact, on the third day)

 

Example: The password must have uppercase letters, lowercase letters, numbers,

password = ____________ #__ which can be input (), custom input may be

A='ABCD.....'

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

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

count_1, count_2, count_3 = False, False, False # to parameter assignment

for i in password:

     if i in A:

        count_1=True

     if i in B:

        count_2=True

     if i in C:

        count_3=True

if count_1 and count_2 and count_3:

   print('OK')

else:

    print ( 'Password must have uppercase letters, lowercase letters, numbers')

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

Example: Calculator

num1, num2 = map (float, input (. 'Num1, Num2: >>') split ( ',')) # 2 digital input simultaneously
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:

#Throw an exception

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

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

Example: random outputs

This is VS code #######

import random

res = random.choice ([ 'rock', 'scissors', 'cloth'])

print(res)

 ######## This is Jupyter

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

 Password input bank (3) for loop ---------

password='151213'
mm = int (input ( 'output code (3 chances :)'))
for i in range(2):
if mm == password:
print ( 'right')
break
else:
print ( 'error', i + 1, 'secondary')
mm = int (input ( 'output code: (3 chances :)'))
else:
print ( 'account lockout')

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

Output random array:

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

print(res)

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

Sequence

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

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

Yesterday example:

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))

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

########昨天写死了,今天要补死了,啊啊啊啊啊

 

 

Guess you like

Origin www.cnblogs.com/sun-love/p/11284235.html