1
Define a function that can accept an integer number as input and print the “It is an even number” if the number is even, otherwise print “It is an odd number”.
1 | def checkValue(n): |
2
Define a function that can accept two strings as input and print the string with maximum length in console. If two strings have the same length, then the function should print al l strings line by line.
1 | def f(s1,s2): |
3
Define a function that can accept two strings as input and concatenate them and then print it in console.
1 | def f(s1,s2): |
4
Define a function that can receive two integral numbers in string form and compute their sum and then print it in console.
分析:字符串转int,然后计算
1 | def f(n1,n2): |
5
Define a function that can convert a integer into a string and print it in console.
int型转字符串
1 | def f(n): |
6
Define a function that can convert a integer into a string and print it in console.
1 | def f(n): |
7
Define a function which can compute the sum of two numbers.
1 | def f(n1,n2): |
8
Define a class, which have a class parameter and have a same instance parameter
1 | class Myclass: |
9
Python has many built-in functions, and if you do not know how to use it, you can read document online or find some books. But Python has a built-in document function for every built-in functions. Please write a program to print some Python built-in functions documents, such as abs(), int(), raw_input() And add document for your own function
分析:使用__doc__()
方法可以输出函数内的注释
10
Write a method which can calculate square value of number
1 | def f(n): |
11
Write a program to compute the frequency of the words from the input. The output should output after sorting the key alphanumerically.
分析:字符串处理
1 | s = input("Please input a sentence:") |
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论