Python-56~60

---56---

Question:

>Print a unicode string "hello world".

Hints:

>Use u'strings' format to define unicode string.

Solution:


---57---

Question:

>Write a program to read an ASCII string and to convert it to a unicode string encoded by utf-8.

Hints:

>Use unicode()/encode() function to convert.

Solution:


---58---

Question:

Write a special comment to indicate a Python source code file is in unicode.


---59---

Question:

>Write a program to compute 1/2+2/3+3/4+...+n/n+1 with a given n input by console (n>0).

Example:

>If the following n is given as input to the program:   5

>Then, the output of the program should be:   3.55

Hints:

>Use float() to convert an integer to a float.Even if not converted it wont cause a problem because python by default understands the data type of a value

Solution:


---60---

Question:

>Write a program to compute:   f(n)=f(n-1)+100 when n>0

and f(0)=0

>with a given n input by console (n>0).

Example:

>If the following n is given as input to the program:    5 

>Then, the output of the program should be:     500

 Hints:

>We can define recursive function in Python.

Solution:


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。