说起来有很长一段时间没有逛博客了,今天也是突发奇想的不知道咋回事就逛起了博客,看到了这篇文章!原作者是在Python2的时候创建的,分享10道python基础练习题,这里面课都是前辈们的智慧结晶啊,总之了:个人觉得,是非常适合小白来练习,一起来看看吧!
Question 1:
* Write a program which can compute the factorial of a given numbers.The results should be printed in a comma-separated sequence on a single line Suppose the following input is supplied to the program: 8
Then, the output should be:40320 *
解法一:
解法二:
(这两个不同的解法可还看得懂?很简单的逻辑思维解题法)
Question 3:
With a given integral number n, write a program to generate a dictionary that contains (i, i x i) such that is an integral number between 1 and n (both included). and then the program should print the dictionary.Suppose the following input is supplied to the program: 8
Then, the output should be:
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}
解法一:
解法二:
(这道题个人还是挺喜欢的,越喜欢就越佩服出题人的智慧)
Question 4:
Write a program which accepts a sequence of comma-separated numbers from console and generate a list and a tuple which contains every number.Suppose the following input is supplied to the program:
34,67,55,33,12,98
Then, the output should be:
['34', '67', '55', '33', '12', '98']
('34', '67', '55', '33', '12', '98')
解法一:
(这道题个人也很喜欢,入门时候基本上百分90的人都有做过吧?)
Question 5:
Define a class which has at least two methods:getString: to get a string from console input
printString: to print the string in upper case.
Also please include simple test function to test the class methods.
解法一:
更多相关CSDN经典:Python基础练习100题内容关注小编敬请期待为你带来更优质的相关文章!
谢谢各位的关注收藏,我们下期再见。
CSDN经典:Python基础练习100题 ( 5~10)汇总大家智慧的结晶下篇