用python統計從鍵盤上輸入的字串中英文字母a z出現的

2021-04-01 06:14:47 字數 1824 閱讀 4823

1樓:匿名使用者

s = input().lower()result = [[e, s.count(e)] for e in set(list(s))]print(result)

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

2樓:凌亂心扉

a = "aa**r3idd4bgs7dlsf9eaf"

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

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

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

例 :'aa**r3idd4bgs7dlsf9eaf',經過去除後,輸出 'a**r3id4bg7lf9e'

a="aa**r3idd4bgs7dlsf9eaf"

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)

3樓:

#!/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)

從鍵盤上輸入字元型資料,若輸入數字字元( 09則將其轉換成相應的整數顯示出來

include main 沒有錯!有什麼問題?從鍵盤上輸入一個字元型資料,若輸入一個數字字元 0 9 則將其轉換成相應的整數 scanf需要以一個回車結束輸入,那麼題目要求的輸入一個字元型資料的要求是否滿足,存疑問。include main c語言作業 編寫一個程式,讀入一個數字字元0 9,將其轉換...

鍵盤上怎樣輸入逗號句號頓號謝謝,鍵盤上頓號怎麼打出來?

謝謝符號在鍵盤上都有的 找下就可以了 dao 專 t 屬 有些輸入法鍵盤上 就是頓號你可以先試試 逗號和句號都好的找 不會真不會吧 鍵盤上都有 用中文輸入法,然後設定中文標點。0 鬱悶啊 你怎麼會看不見。不是吧?你都是助理二級吔!鬱悶!鍵盤上頓號怎麼打出來?在電腦上打頓號比起復飛符號制要難一些,因為...

在電腦鍵盤上怎樣輸入2的平方,鍵盤上平方怎麼打

先打出2,再按住alt鍵,同是在小鍵盤上輸入178,就ok了 用輸入法吧。鍵盤上平方怎麼打 先把輸入法調為英文狀態 然後按住alt鍵 在右邊小鍵盤輸入178,就是 若輸入179,則是立方,如二的平方,2 2,shift鍵 6鍵按出 電腦鍵盤上平方,怎麼打出來?選中,然後選擇選單 格式 字型,中間那裡...