python中輸入字串,統計字串中大小寫英文本母各有多少

時間 2021-05-02 20:11:54

1樓:匿名使用者

str_1=input("請輸入乙個字串:")lower=0

upper=0

for i in str_1:

if i.islower():

lower += 1

elif i.isupper():

upper += 1

print("有%s個大寫字母"%upper)print("有%s個小寫字母"%lower)

2樓:換證薇

str_1=input("請輸入乙個字串:")numc=0

nums=0

numo=0

i=0len_str=len(str_1)while i<=len_str:

i += 1

if(str[i]>="a") and (str[i]<="z"):

numc=numc+1

if(str[i]>="a") and (str[i]<="z"):

nums=nums+1

else:

numo=numo+1

print("您輸入的字串統計結果是:",len_str)print("有%s個大寫字母"%numc)print("有%s個小寫字母"%nums)print("有%s個其他字母"%numo)or# python3.6

s = input("請輸入乙個字串:")a = b = c = 0

for i in s:

if 'a' <= i <= 'z':

a += 1

elif 'a' <= i <= 'z':

b += 1

else:

c += 1

print("您輸入的字串統計結果是:",len(str))print(f"有個大寫字母")

print(f"有個小寫字母")

print(f"有個其他字母")

3樓:杯具——悲劇

# python中輸入字串,統計字串中大小寫英文本母各有多少個?

class countnum(object):

def __init__(self):

s = input("input a string")self.s = s

def judge(self):

bigger = 0

smaller = 0

for i in self.s:

if i < 'a' or i > 'z':

continue

elif 'a' < i < 'z':

bigger += 1

elif 'a' < i < 'z':

smaller += 1

return bigger, smallerif __name__ == '__main__':

p = countnum()

big, small = p.judge()print("大寫字母%d個" % big)print("小寫字母%d個" % small)

python數出字串中大小寫字母的 5

4樓:匿名使用者

str_1=input("請輸入乙個字串:")numc=0

nums=0

numo=0

i=0len_str=len(str_1)while i<=len_str:

i += 1

if(str[i]>="a") and (str[i]<="z"):

numc=numc+1

if(str[i]>="a") and (str[i]<="z"):

nums=nums+1

else:

numo=numo+1

print("您輸入的字串統計結果是:",len_str)print("有%s個大寫字母"%numc)print("有%s個小寫字母"%nums)print("有%s個其他字母"%numo)or# python3.6

s = input("請輸入乙個字串:")a = b = c = 0

for i in s:

if 'a' <= i <= 'z':

a += 1

elif 'a' <= i <= 'z':

b += 1

else:

c += 1

print("您輸入的字串統計結果是:",len(str))print(f"有個大寫字母")

print(f"有個小寫字母")

print(f"有個其他字母")

用python寫程式實現:輸入一字串,分別統計其中的英文本母個數,空格、數字和其他字元。

5樓:匿名使用者

你好:那這個就是python的正規表示式的應用了;

6樓:匿名使用者

有個count函式,可以分別計數啊

7樓:匿名使用者

判斷ascii碼應該就可以了、、

8樓:匿名使用者

python中有些內建函式很逆天的。

python,編寫程式,統計大小寫字母,數字及其他字元的數量,並以字典形式輸出

9樓:凌亂心扉

a = "aasmr3idd4bgs7dlsf9eaf"

請將a字串的數字取出,並輸出成乙個新的字串。

請統計a字串出現的每個字母的出現次數(忽略大小寫,a與a是同乙個字母),並輸出成乙個字典。 例

請去除a字串多次出現的字母,僅留最先出現的乙個,大小寫不敏感。

例 :'aasmr3idd4bgs7dlsf9eaf',經過去除後,輸出 'asmr3id4bg7lf9e'

a="aasmr3idd4bgs7dlsf9eaf"

def fun1_2(x):#1&2

x=x.lower()#大小寫轉換

num=

dic={}

for i in x:

if i.isdigit():#判斷如果為數字,請將a字串的數字取出,並輸出乙個新的字串

else:#2請統計a字串出現每個字母的出現次數(忽視大小寫),並輸出乙個字典。例:

if i in dic:

continue

else:

dic=x.count(i)

new=''.join(num)

print"the new numbers string is:"+new

print"the dictionary is:%s"%dic

fun1_2(a)

def fun3(x):

x=x.lower()

new3=

for i in x:

if i in new3:

continue

else:

print''.join(new3)

fun3(a)

10樓:

#!/usr/bin/python

# -*- coding:utf-8 -*-# @file    : statistics.py"""統計字串中大寫的字母、小寫的字母、數字及其他字元的個數,以字典形式返回

"""def statistic_string(ostr):

"""統計字串中大寫的字母、小寫的字母、數字及其他字元的個數,以字典形式返回

"""uppers = 0

lowers = 0

digits = 0

others = 0

odict = {}

for istr in ostr:

if istr.isupper():

uppers += 1

elif istr.islower():

lowers += 1

elif istr.isdigit():

digits += 1

else:

others += 1

else:

odict.setdefault('uppers', uppers)odict.setdefault('lowers', lowers)odict.

setdefault('digits', digits)odict.setdefault('others', others)return odict

if __name__ == '__main__':

astr = raw_input(u'請輸入乙個字串:')print statistic_string(astr)

python 輸入一行字元,分別統計出其中英文本母,空格,數字和其他字元的個數

11樓:匿名使用者

輸入一行字元=input("請輸入任意資料:")

數字個數=len(list(i for i in 輸入一行字元 if i.isdigit()==1))

中英文本母個數=len(list((i for i in 輸入一行字元 if i.isalpha()==1)))

空格個數=len(list(i for i in 輸入一行字元 if i==" "))

其他個數=len(輸入一行字元)-數字個數-中英文本母個數-空格個數

print("中有個數字,個中英文本母,個空格個數,個其他".format(輸入一行字元,數字個數,中英文本母個數,空格個數,其他個數))

12樓:藍紫

#準備國二,第四章 三.3

a=input()

e=d=f=g=0

for i in a:

if i.isalpha() :

e+=1

elif i==" ":

d+=1

elif i.isdigit():

f+=1

else:

g+=1

print('文字{},數字{},空格{},其他{}'.format(e,f,d,g))

13樓:匿名使用者

這是我用python3寫的

a=input()

b="abcdefghigklmnopqrstuvwxyz"

m="0123456789"

c=str.upper(b)

d=0e=0

n=0q=0

h=0z=len(a)

for i in range(z):

if a[i] in b:

d=d+1

elif a[i] in c:

e=e+1

elif a[i] in m:

n=n+1

elif a[i] in " ":

q=q+1

else:

h=h+1

print(d,e,n,q,h)

14樓:

ostr = raw_input('請輸入一串字元:')str_num = 0

spac_num = 0

figue_num = 0

for strs in ostr:

if strs.isalpha():

str_num +=1

elif strs.isdigit():

figue_num +=1

elif strs == ' ':

spac_num +=1

else:

pass

print '英文本母有:%d' %str_numprint '數字有:%d'%figue_numprint '空格有:%d'%spac_num**如上

編寫函式,由實引數傳來字串,統計此字串中字母,數

取什麼名字才好呢啊哦 include using namespace std void main cout number include main count digits,white space,others printf digits for i 0 i 10 i printf d ndigit...

python中怎麼在字串結尾新增新字元?

字串是不可變的,只能重新構建字串然後賦值。s ab s c s abc excel中怎麼在字串中新增字元 1 在電腦上用2007版excel軟體開啟目標檔案,選中另一單元格。2 然後在單元格中輸入公式 a1 你是 雙引號中的就是要新增的字元。4 完成以上設定後,即可在excel中為字串中新增字元。1...

C 中怎樣刪除字串中與另字串中相同的字元

include include include using namespace std int main cout str1 如何在c 的字串中刪除某個字串 千鋒教育 利用c的strstr函式查詢字串,然後strcpy拷貝覆蓋它。include int main 這裡只刪除了一處匹配的字串,如果有多...