新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python程序:檢查字符是元音還是輔音
創(chuàng)新互聯(lián)Python教程:

創(chuàng)新互聯(lián)公司是一家專注于網(wǎng)站設(shè)計、網(wǎng)站制作與策劃設(shè)計,大通網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)10多年,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務涵蓋:大通等地區(qū)。大通做網(wǎng)站價格咨詢:18982081108
寫一個 Python 程序來檢查字符是元音還是輔音,并給出一個實例。
Python 程序檢查字符是元音還是輔音
這個 python 程序允許用戶輸入任何字符。接下來,我們使用 If Else 語句來檢查用戶給定的字符是元音還是輔音。
這里, If 語句檢查字符是否等于 A、E、I、O、u、A、E、I、O、u,如果為 TRUE,則為元音。否則就是輔音。
# Python Program to check character is Vowel or Consonant
ch = input("Please Enter Your Own Character : ")
if(ch == 'a' or ch == 'e' or ch == 'i' or ch == 'o' or ch == 'u' or ch == 'A'
or ch == 'E' or ch == 'I' or ch == 'O' or ch == 'U'):
print("The Given Character ", ch, "is a Vowel")
else:
print("The Given Character ", ch, "is a Consonant")
使用 ASCII 值驗證字符是元音還是輔音的 Python 程序
在這個 Python 的例子中,我們使用 ASCII 值來檢查給定的字符是元音還是輔音。
ch = input("Please Enter Your Own Character : ")
if(ord(ch) == 65 or ord(ch) == 69 or ord(ch) == 73
or ord(ch) == 79 or ord(ch) == 85
or ord(ch) == 97 or ord(ch) == 101 or ord(ch) == 105
or ord(ch) == 111 or ord(ch) == 117):
print("The Given Character ", ch, "is a Vowel")
elif((ord(ch) >= 97 and ord(ch) <= 122) or (ord(ch) >= 65 and ord(ch) <= 90)):
print("The Given Character ", ch, "is a Consonant")
Please Enter Your Own Character : E
The Given Character E is a Vowel
>>>
Please Enter Your Own Character : l
The Given Character l is a Consonant 當前標題:Python程序:檢查字符是元音還是輔音
網(wǎng)站鏈接:http://fisionsoft.com.cn/article/dpdphcj.html


咨詢
建站咨詢
