Hướng dẫn how do you find the inputs of a vowel in python? - làm thế nào để bạn tìm thấy đầu vào của một nguyên âm trong python?

Trong bài đăng này, chúng tôi sẽ viết một chương trình Python để kiểm tra xem ký tự đã nhập là nguyên âm hay phụ âm.Python program to check whether the entered character is vowel or consonant.

Mã Python

Trong chương trình này, người dùng được yêu cầu nhập một ký tự. Chương trình kiểm tra xem ký tự đã nhập bằng nguyên âm chữ thường hay nguyên âm chữ hoa, nếu đó là chương trình in một thông báo nói rằng ký tự là nguyên âm khác mà nó in rằng ký tự là phụ âm.character is a Vowel else it prints that the character is a Consonant.

# taking user input
ch = input("Enter a character: ")

if(ch=='A' or ch=='a' or ch=='E' or ch =='e' or ch=='I'
 or ch=='i' or ch=='O' or ch=='o' or ch=='U' or ch=='u'):
    print(ch, "is a Vowel")
else:
    print(ch, "is a Consonant")

Output:

Hướng dẫn how do you find the inputs of a vowel in python? - làm thế nào để bạn tìm thấy đầu vào của một nguyên âm trong python?

Bài viết liên quan:

  1. C chương trình để kiểm tra nguyên âm hoặc phụ âm
  2. Chương trình Java để kiểm tra nguyên âm hoặc phụ âm
  3. Chương trình Python để kiểm tra xem nhân vật có bảng chữ cái hay không
  4. Chương trình Python để kiểm tra xem số chẵn hoặc lẻ
  5. Chương trình Python để in Hello World

Cập nhật lần cuối vào ngày 19 tháng 8 năm 2022 21:50:48 (UTC/GMT +8 giờ)

Python Basic: Bài tập-24 với giải pháp

Viết một chương trình Python để kiểm tra xem một chữ cái đã qua có phải là nguyên âm hay không.

Trình bày bằng hình ảnh:

Hướng dẫn how do you find the inputs of a vowel in python? - làm thế nào để bạn tìm thấy đầu vào của một nguyên âm trong python?

Giải pháp mẫu :- :-

Mã Python:

def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

Đầu ra mẫu:

False                                                                                                         
True 

Flowchart:

Hướng dẫn how do you find the inputs of a vowel in python? - làm thế nào để bạn tìm thấy đầu vào của một nguyên âm trong python?

Trực quan hóa thực thi mã Python:

Công cụ sau đây trực quan hóa những gì máy tính đang làm từng bước khi nó thực hiện chương trình đã nói:

Trình chỉnh sửa mã Python:

Có một cách khác để giải quyết giải pháp này? Đóng góp mã của bạn (và nhận xét) thông qua Disqus.

Trước đây: Viết một chương trình Python để có được các bản sao N (không âm) của 2 ký tự đầu tiên của một chuỗi nhất định. Trả về N bản sao của toàn bộ chuỗi nếu độ dài nhỏ hơn 2.DEXT: Viết chương trình Python để kiểm tra xem giá trị được chỉ định có chứa trong một nhóm các giá trị hay không. Write a Python program to get the n (non-negative integer) copies of the first 2 characters of a given string. Return the n copies of the whole string if the length is less than 2.
Next: Write a Python program to check whether a specified value is contained in a group of values.

Mức độ khó của bài tập này là gì?

Kiểm tra kỹ năng lập trình của bạn với bài kiểm tra của W3Resource.

Python: Lời khuyên trong ngày

Sử dụng năng suất để tạo ra một trình lặp đơn giản:

>>> def foo(lst):
>>>   for x in lst:
>>>       yield x
>>>       yield x*2

>>> a = [1, 3]
>>> list(foo(a))
[1, 2, 3, 6]


  • Bài tập: Top 16 chủ đề phổ biến nhất hàng tuần
  • Bài tập SQL, Thực hành, Giải pháp - Tham gia
  • Bài tập SQL, Thực hành, Giải pháp - Quan sát phụ
  • JavaScript Basic - Bài tập, Thực hành, Giải pháp
  • Java Array: Bài tập, Thực hành, Giải pháp
  • C Bài tập lập trình, Thực hành, Giải pháp: Tuyên bố có điều kiện
  • Cơ sở dữ liệu nhân sự - Sắp xếp bộ lọc: Bài tập, Thực hành, Giải pháp
  • C Bài tập lập trình, Thực hành, Giải pháp: Chuỗi
  • Các loại dữ liệu Python: Từ điển - Bài tập, Thực hành, Giải pháp
  • Câu đố lập trình Python - Bài tập, Thực hành, Giải pháp
  • Mảng C ++: Bài tập, Thực hành, Giải pháp
  • Báo cáo và vòng lặp có điều kiện JavaScript - Bài tập, Thực hành, Giải pháp
  • Thuật toán cơ bản C# Sharp: Bài tập, Thực hành, Giải pháp
  • Python Lambda - Bài tập, Thực hành, Giải pháp
  • Python Pandas DataFrame: Bài tập, Thực hành, Giải pháp
  • Công cụ chuyển đổi
  • JavaScript: HTML Mẫu xác thực


Đếm nguyên âm: Từ điển cách
Examples: 
 

In a simple way
Input : Geeks for Geeks
Output :
5
['e', 'e', 'o', 'e', 'e']

This is in a different way
Input : Geeks for Geeks
Output : {'u': 0, 'o': 1, 'e': 4, 'a': 0, 'i': 0}

Đếm nguyên âm: Chuỗi cách

Trong phương thức này, chúng tôi sẽ lưu trữ tất cả các nguyên âm trong một chuỗi và sau đó chọn mọi ký tự từ chuỗi được yêu cầu và kiểm tra xem nó có nằm trong chuỗi nguyên âm hay không. Chuỗi nguyên âm bao gồm tất cả các nguyên âm với cả hai trường hợp vì chúng tôi không bỏ qua các trường hợp ở đây. Nếu nguyên âm gặp phải thì đếm được tăng lên và lưu trữ trong danh sách và cuối cùng được in. & NBSP; & nbsp;
 

Python3

def Check_Vow(string, vowels):

____10

def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

1
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

2
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

3
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

4

def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

0
False                                                                                                         
True 
3
False                                                                                                         
True 
4
False                                                                                                         
True 
5
False                                                                                                         
True 
6

def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

0
False                                                                                                         
True 
3
False                                                                                                         
True 
9

def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

7
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

2
>>> def foo(lst):
>>>   for x in lst:
>>>       yield x
>>>       yield x*2

>>> a = [1, 3]
>>> list(foo(a))
[1, 2, 3, 6]
2

>>> def foo(lst):
>>>   for x in lst:
>>>       yield x
>>>       yield x*2

>>> a = [1, 3]
>>> list(foo(a))
[1, 2, 3, 6]
3
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

2
>>> def foo(lst):
>>>   for x in lst:
>>>       yield x
>>>       yield x*2

>>> a = [1, 3]
>>> list(foo(a))
[1, 2, 3, 6]
5

>>> def foo(lst):
>>>   for x in lst:
>>>       yield x
>>>       yield x*2

>>> a = [1, 3]
>>> list(foo(a))
[1, 2, 3, 6]
6

Output:  
 

5
['e', 'e', 'o', 'e', 'e']

Đếm nguyên âm: Từ điển cách

Điều này cũng thực hiện cùng một nhiệm vụ nhưng theo một cách khác. Trong phương pháp này, chúng tôi tạo thành một từ điển với các nguyên âm và tăng chúng khi gặp nguyên âm. Trong phương pháp này, chúng tôi sử dụng phương thức Fold Case để bỏ qua các trường hợp, theo đó chúng tôi tạo thành một từ điển nguyên âm với khóa làm nguyên âm. Đây là một cách tốt hơn và hiệu quả để kiểm tra và tìm số lượng của mỗi nguyên âm có trong một chuỗi. & Nbsp; & nbsp;
 

Python3

def Check_Vow(string, vowels):

____10

def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

1
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

2
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

3
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

4

def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

7
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

2
>>> def foo(lst):
>>>   for x in lst:
>>>       yield x
>>>       yield x*2

>>> a = [1, 3]
>>> list(foo(a))
[1, 2, 3, 6]
2

>>> def foo(lst):
>>>   for x in lst:
>>>       yield x
>>>       yield x*2

>>> a = [1, 3]
>>> list(foo(a))
[1, 2, 3, 6]
3
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

2
>>> def foo(lst):
>>>   for x in lst:
>>>       yield x
>>>       yield x*2

>>> a = [1, 3]
>>> list(foo(a))
[1, 2, 3, 6]
5

Đếm nguyên âm: Từ điển cách

Điều này cũng thực hiện cùng một nhiệm vụ nhưng theo một cách khác. Trong phương pháp này, chúng tôi tạo thành một từ điển với các nguyên âm và tăng chúng khi gặp nguyên âm. Trong phương pháp này, chúng tôi sử dụng phương thức Fold Case để bỏ qua các trường hợp, theo đó chúng tôi tạo thành một từ điển nguyên âm với khóa làm nguyên âm. Đây là một cách tốt hơn và hiệu quả để kiểm tra và tìm số lượng của mỗi nguyên âm có trong một chuỗi. & Nbsp; & nbsp;

def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

0
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

7
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

2
In a simple way
Input : Geeks for Geeks
Output :
5
['e', 'e', 'o', 'e', 'e']

This is in a different way
Input : Geeks for Geeks
Output : {'u': 0, 'o': 1, 'e': 4, 'a': 0, 'i': 0}
2

____10

In a simple way
Input : Geeks for Geeks
Output :
5
['e', 'e', 'o', 'e', 'e']

This is in a different way
Input : Geeks for Geeks
Output : {'u': 0, 'o': 1, 'e': 4, 'a': 0, 'i': 0}
4
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

2
In a simple way
Input : Geeks for Geeks
Output :
5
['e', 'e', 'o', 'e', 'e']

This is in a different way
Input : Geeks for Geeks
Output : {'u': 0, 'o': 1, 'e': 4, 'a': 0, 'i': 0}
6
In a simple way
Input : Geeks for Geeks
Output :
5
['e', 'e', 'o', 'e', 'e']

This is in a different way
Input : Geeks for Geeks
Output : {'u': 0, 'o': 1, 'e': 4, 'a': 0, 'i': 0}
7
In a simple way
Input : Geeks for Geeks
Output :
5
['e', 'e', 'o', 'e', 'e']

This is in a different way
Input : Geeks for Geeks
Output : {'u': 0, 'o': 1, 'e': 4, 'a': 0, 'i': 0}
8

def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

7
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

2
>>> def foo(lst):
>>>   for x in lst:
>>>       yield x
>>>       yield x*2

>>> a = [1, 3]
>>> list(foo(a))
[1, 2, 3, 6]
2

>>> def foo(lst):
>>>   for x in lst:
>>>       yield x
>>>       yield x*2

>>> a = [1, 3]
>>> list(foo(a))
[1, 2, 3, 6]
3
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

2
>>> def foo(lst):
>>>   for x in lst:
>>>       yield x
>>>       yield x*2

>>> a = [1, 3]
>>> list(foo(a))
[1, 2, 3, 6]
5

Output:  
 

{'u': 0, 'o': 1, 'e': 4, 'a': 0, 'i': 0}

Đếm nguyên âm: Từ điển cáchCounting vowels: regex way 

Điều này cũng thực hiện cùng một nhiệm vụ nhưng theo một cách khác. Trong phương pháp này, chúng tôi tạo thành một từ điển với các nguyên âm và tăng chúng khi gặp nguyên âm. Trong phương pháp này, chúng tôi sử dụng phương thức Fold Case để bỏ qua các trường hợp, theo đó chúng tôi tạo thành một từ điển nguyên âm với khóa làm nguyên âm. Đây là một cách tốt hơn và hiệu quả để kiểm tra và tìm số lượng của mỗi nguyên âm có trong một chuỗi. & Nbsp; & nbsp;

Python3

def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

0
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

7
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

2
In a simple way
Input : Geeks for Geeks
Output :
5
['e', 'e', 'o', 'e', 'e']

This is in a different way
Input : Geeks for Geeks
Output : {'u': 0, 'o': 1, 'e': 4, 'a': 0, 'i': 0}
2

def Check_Vow(string, vowels):

____10

def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

1
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

2
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

3
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

4

def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

0
False                                                                                                         
True 
3
False                                                                                                         
True 
4
False                                                                                                         
True 
5def9

def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

7
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

2
>>> def foo(lst):
>>>   for x in lst:
>>>       yield x
>>>       yield x*2

>>> a = [1, 3]
>>> list(foo(a))
[1, 2, 3, 6]
2

____10

In a simple way
Input : Geeks for Geeks
Output :
5
['e', 'e', 'o', 'e', 'e']

This is in a different way
Input : Geeks for Geeks
Output : {'u': 0, 'o': 1, 'e': 4, 'a': 0, 'i': 0}
4
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

2
In a simple way
Input : Geeks for Geeks
Output :
5
['e', 'e', 'o', 'e', 'e']

This is in a different way
Input : Geeks for Geeks
Output : {'u': 0, 'o': 1, 'e': 4, 'a': 0, 'i': 0}
6
In a simple way
Input : Geeks for Geeks
Output :
5
['e', 'e', 'o', 'e', 'e']

This is in a different way
Input : Geeks for Geeks
Output : {'u': 0, 'o': 1, 'e': 4, 'a': 0, 'i': 0}
7
In a simple way
Input : Geeks for Geeks
Output :
5
['e', 'e', 'o', 'e', 'e']

This is in a different way
Input : Geeks for Geeks
Output : {'u': 0, 'o': 1, 'e': 4, 'a': 0, 'i': 0}
8

def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

7
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

2
>>> def foo(lst):
>>>   for x in lst:
>>>       yield x
>>>       yield x*2

>>> a = [1, 3]
>>> list(foo(a))
[1, 2, 3, 6]
2

>>> def foo(lst):
>>>   for x in lst:
>>>       yield x
>>>       yield x*2

>>> a = [1, 3]
>>> list(foo(a))
[1, 2, 3, 6]
3
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
print(is_vowel('c'))
print(is_vowel('e'))

2
>>> def foo(lst):
>>>   for x in lst:
>>>       yield x
>>>       yield x*2

>>> a = [1, 3]
>>> list(foo(a))
[1, 2, 3, 6]
5

Output:

5
['e', 'e', 'o', 'e', 'e']