46 Simple Python Exercises-Very simple exercises

4、Write a function that takes a character (i.e. a string of length 1) and returns True if it is a vowel, False otherwise.

def if_vowel(a):    a=a.lower()    if a in(‘a‘,‘e‘,‘i‘,‘o‘,‘u‘):        return True    else:        return Falseprint(if_vowel(‘A‘))

原文地址:https://www.cnblogs.com/wangyanyan/p/10737264.html

时间: 2024-10-10 13:02:34

46 Simple Python Exercises-Very simple exercises的相关文章

46 Simple Python Exercises (前20道题)

46 Simple Python Exercises This is version 0.45 of a collection of simple Python exercises constructed (but in many cases only found and collected) by Torbj?rn Lager ([email protected]). Most of them involve characters, words and phrases, rather than

46 Simple Python Exercises 16-22题

会贴出原题和答案,答案不是最优的,也反映了我的学习过程,如果有时间会更新优化的代码. Write a function filter_long_words() that takes a list of words and an integer n and returns the list of words that are longer than n. #Write a function filter_long_words() that takes a list of words # and a

46 Simple Python Exercises-Higher order functions and list comprehensions

26. Using the higher order function reduce(), write a function max_in_list() that takes a list of numbers and returns the largest one. Then ask yourself: why define and call a new function, when I can just as well call the reduce() function directly?

Simple Python Dictionary :)

摘自 http://github.com/panweizeng/home/blob/master/code/python/dict/dict.py 支持简单的Ch to En 和En to Ch我把它放在 /usr/bin/dict 1234567891011 $ dict 白痴 单词:白痴 音标: bái chī 释义:idiot idiocy 例句:他很聪明,但有时举止像是白痴. 翻译:He is intelligent, but sometimes he behaves like an i

Beginner : Simple Python test

#!/usr/local/bin/python# -*- coding: utf-8 -*-.# line of utf-8 is for multi-language# optional 4-spaces before line rule for Python. import syssys.path.append("/homes/sli/pexpect-2.3/")import pexpectimport timeimport reimport os print "Welc

Python Web Scraper - Simple Url Request

from urllib.request import urlopen html = urlopen("http://www.baidu.com") print(html.read()) 注意: 以上代码基于Python 3.x

MITx: 6.00.1x Introduction to Computer Science and Programming Using Python Week 2: Simple Programs 4. Functions

ESTIMATED TIME TO COMPLETE: 18 minutes We can use the idea of bisection search to determine if a character is in a string, so long as the string is sorted in alphabetical order. First, test the middle character of a string against the character you'r

python 使用Django Simple Captcha之缺少PIL模块

需要安装PIL模块: yum install python-devel yum install libjpeg libjpeg-devel zlib zlib-devel freetype freetype-devel lcms lcms-devel yum install python-imaging

leetcode 46 Permutations Python 实现(回溯算法)

Given a collection of distinct integers, return all possible permutations. Example: Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]] 回溯算法自己的一个思路如下:需要保留数字使用情况,my_nums增加和删除元素等操作 1 class Solution: 2 def permute(self, nums: Li