程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python] learning notes week10-1 cycle

編輯:Python

【PYTHON】 Rhombic array # character string # loop

Title Description

Enter a n, Output the corresponding diamond array

Input

3

Output

    *

   ***

 *****

*******

 *****

  ***

   *

The sample input

3

Sample output

* *** ***** *** *

c=eval(input())
def stars5(n):
RANGE1 = [2*i+1 for i in range(n)]
RANGE2 = [2*i+1 for i in range(n)[::-1]][1:]
RANGE = RANGE1 + RANGE2
RANGE_1 = [i for i in range(n)[::-1]]
RANGE_2 = [i for i in range(n)[1:]]
RANGE_12 = RANGE_1 + RANGE_2
for i in range(len(RANGE)):
print (' '*RANGE_12[i] + '*'*RANGE[i])
if __name__ == "__main__":
stars5(c)

PYTHON】 Count the number of different types of characters in the string # character string # loop

Title Description

This topic requires reading a string , Count the letters in the string 、 Numbers 、 Space 、 The number of other characters .

Input

Enter a line of string consisting of any character .

Output

 Count the letters in the string 、 Numbers 、 Space 、 The number of other characters .

The sample input

2a and Am3,MNak888!..

Sample output

letters=10,digits=5,spaces=2,others=4

a=input()
isalpha=0
isdigit=0
isspace=0
other=0
for i in a:
if i.isalpha():
isalpha=isalpha+1
elif i.isdigit():
isdigit=isdigit+1
elif i.isspace():
isspace=isspace+1
else:
other=other+1
print("letters={},digits={},spaces={},others={}".format(isalpha,isdigit,isspace,other))

【PYTHON】 Password strength # character string

Title Description

This topic requires you to input the password string according to ( String length greater than 6), Output password strength . The rules : Password requirements can only contain capital letters 、 Lowercase letters 、 Numbers and underscores , If only one of them is included , Then the password strength is 1; If two of them are included , Then the password strength is 2; If three of them are included , Then the password strength is 3; If you include four of them , Then the password strength is 4.

Input

The input length is greater than 6 String .

Output

Output password strength .

The sample input

123456789

Sample output

1

a=input()
islower=0
isupper=0
isdigit=0
other=0
for i in a:
if i.islower():
islower=1
elif i.isupper():
isupper=1
elif i.isdigit():
isdigit=1
elif i=="_":
other=1
print("{}".format(islower+isupper+isdigit+other))

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved