日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python程序输入一个字符串并查找总数的大写和小写字母

發布時間:2025/3/11 python 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python程序输入一个字符串并查找总数的大写和小写字母 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Given a string str1 and we have to count the total numbers of uppercase and lowercase letters.

給定字符串str1 ,我們必須計算大寫和小寫字母的總數。

Example:

例:

Input: "Hello World!"Output:Uppercase letters: 2Lowercase letters: 8Input: "[email?protected]"Output:Uppercase letters: 1Lowercase letters: 4

Method 1:

方法1:

(Manual) By checking each character of the string with a range of uppercase and lowercase letters using the conditional statement.

(手動)通過使用條件語句檢查字符串中每個字符的大小寫范圍。

print("Input a string: ") str1 = input()no_of_ucase, no_of_lcase = 0,0for c in str1:if c>='A' and c<='Z':no_of_ucase += 1if c>='a' and c<='z':no_of_lcase += 1print("Input string is: ", str1) print("Total number of uppercase letters: ", no_of_ucase) print("Total number of lowercase letters: ", no_of_lcase)

Output

輸出量

RUN 1: Input a string: Hello World! Input string is: Hello World! Total number of uppercase letters: 2 Total number of lowercase letters: 8RUN 2: nput a string: [email?protected] Input string is: [email?protected] Total number of uppercase letters: 1 Total number of lowercase letters: 4

Method 2:

方法2:

By using islower() and isupper() methods

通過使用islower()和isupper()方法

print("Input a string: ") str1 = input()no_of_ucase, no_of_lcase = 0,0for c in str1:no_of_ucase += c.isupper()no_of_lcase += c.islower()print("Input string is: ", str1) print("Total number of uppercase letters: ", no_of_ucase) print("Total number of lowercase letters: ", no_of_lcase)

Output

輸出量

RUN 1: Input a string: Hello World! Input string is: Hello World! Total number of uppercase letters: 2 Total number of lowercase letters: 8RUN 2: nput a string: [email?protected] Input string is: [email?protected] Total number of uppercase letters: 1 Total number of lowercase letters: 4

翻譯自: https://www.includehelp.com/python/program-to-input-a-string-and-find-total-number-of- uppercase-and-lowercase-letters.aspx

總結

以上是生活随笔為你收集整理的Python程序输入一个字符串并查找总数的大写和小写字母的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。