日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python程序:統(tǒng)計字符串中元音和輔音

創(chuàng)新互聯(lián)Python教程:

創(chuàng)新互聯(lián)建站主要從事成都網(wǎng)站建設(shè)、成都網(wǎng)站制作、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)卓資,十余年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):028-86922220

寫一個 Python 程序,使用 For 循環(huán)和 ASCII 值計算字符串中的元音和輔音,并給出一個實際例子。

計算字符串中元音和輔音的 Python 程序示例 1

這個 python 程序允許用戶輸入一個字符串。接下來,它使用 For 循環(huán)計算該字符串中元音和輔音的總數(shù)。首先,我們使用 Python For 循環(huán)來迭代字符串中的每個字符。在 For Loop 中,我們使用 If 語句檢查字符串字符是否為 A、E、I、O、u、A、E、I、O、u,如果為真,則增加元音值,否則增加輔音值

# Python Program to Count Vowels and Consonants in a String

str1 = input("Please Enter Your Own String : ")
vowels = 0
consonants = 0

for i in str1:
    if(i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u'
       or i == 'A' or i == 'E' or i == 'I' or i == 'O' or i == 'U'):
        vowels = vowels + 1
    else:
        consonants = consonants + 1

print("Total Number of Vowels in this String = ", vowels)
print("Total Number of Consonants in this String = ", consonants)

Python 計算字符串輸出中的元音和輔音

Please Enter Your Own String : Hello WOrld
Total Number of Vowels in this String =  3
Total Number of Consonants in this String =  8
>>> 
Please Enter Your Own String : Python Programs
Total Number of Vowels in this String =  3
Total Number of Consonants in this String =  12

計算字符串中元音和輔音的程序示例 2

在這個程序中,我們使用降低功能將字符串覆蓋為小寫。這樣,您只能在 Python If 語句中使用 a、e、I、o、u(避免大寫字母)。

# Python Program to Count Vowels and Consonants in a String

str1 = input("Please Enter Your Own String : ")
vowels = 0
consonants = 0
str1.lower()

for i in str1:
    if(i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u'):
        vowels = vowels + 1
    else:
        consonants = consonants + 1

print("Total Number of Vowels in this String = ", vowels)
print("Total Number of Consonants in this String = ", consonants)

計算元音和輔音總數(shù)的 Python 程序示例 3

這個程序使用 ASCII 值來查找元音和輔音。建議大家參考 ASCII 表文章了解 ASCII 值。

# Python Program to Count Vowels and Consonants in a String

str1 = input("Please Enter Your Own String : ")
vowels = 0
consonants = 0
str1.lower()

for i in str1:
    if(ord(i) == 65 or ord(i) == 69 or ord(i) == 73
       or ord(i) == 79 or ord(i) == 85
       or ord(i) == 97 or ord(i) == 101 or ord(i) == 105
       or ord(i) == 111 or ord(i) == 117):
        vowels = vowels + 1
    elif((ord(i) >= 97 and ord(i) <= 122) or (ord(i) >= 65 and ord(i) <= 90)):
        consonants = consonants + 1

print("Total Number of Vowels in this String = ", vowels)
print("Total Number of Consonants in this String = ", consonants)

Python 計算字符串輸出中的元音和輔音

Please Enter Your Own String : Python Examples
Total Number of Vowels in this String =  4
Total Number of Consonants in this String =  10
>>> 
Please Enter Your Own String : Learn Python Programming
Total Number of Vowels in this String =  6
Total Number of Consonants in this String =  16
>>> 

網(wǎng)站標(biāo)題:Python程序:統(tǒng)計字符串中元音和輔音
網(wǎng)頁鏈接:http://www.5511xx.com/article/djhpsse.html