用于检查字母是元音还是辅音的程序

问题描述 投票:-1回答:2

我是python的初学者,并尝试使用list和for循环编写一个程序来查找字母是元音还是辅音

代码如下:

    al=input("Enter the alphabet")

    list=['a','e','i','o','u']


    for p in list:
      if al==p:
          print("The alphabet is a vowel")


    else:
      print("The alphabet is a consonant")

输出为:

C:\ Users \ dell \ PycharmProjects \ HelloWorld \ venv \ Scripts \ python.exe

C:/Users/dell/PycharmProjects/HelloWorld/app.py

输入字母]

退出代码为0的处理完成

有人可以告诉我我要去哪里哪里

我是python的初学者,并尝试使用list和for循环编写一个程序来查找字母是元音还是辅音。代码如下:al = input(“ Enter the Alphabet”)list = ['a', 'e'...

python list for-loop if-statement pycharm
2个回答
0
投票

有四个问题:


0
投票

else不能按照您认为的方式工作。仅当没有break退出循环时才执行。 (请注意,它附加到for循环,而不是if语句。)


0
投票
al=input("Enter the alphabet")
list=['a','e','i','o','u']
if al in list:
  print("The alphabet is a vowel")
else:
  print("The alphabet is a consonant")
© www.soinside.com 2019 - 2024. All rights reserved.