打卡记录
- 学号:1901090022
- 学习课程:Introduction to Computer Science and Programming in Python
- 学习内容:Problem Set 0 (ZIP - 2.0MB)
- 打卡天数:D01
作业要求(简述):
Write a program that does the following in order:
- Asks the user to enter a number “x”;
- Asks the user to enter a number “y”;
- Prints out number “x”, raised to the power “y”.
- Prints out the log (base 2) of “x”.
Use Spyder to create your program, and save your code in a file named ‘ps0.py’. An example of an interaction with your program is shown below. The words printed in blue are ones the computer should print, based on your commands, while the words in black are an example of a user’s input. The colors are simply here to help you distinguish the two components.
1 | Enter number x: 2 |
作业心得
根据提示,本章作业涉及的知识点如下:
- print / input 函数的使用,可以参考以下文章
- python中的基础数学运算,pow函数; math库的math.pow/log2函数
- numpy库的log2函数
程序的实现过程中,遇到几点需要注意的:
- input函数返回的是str类型,需要通过int函数转化才能进行运算,否则会报错
TypeError: unsupported operand type(s) for ** or pow(): ‘str’ and ‘int’”
- 一般的数据计算,math库也足够了,numpy提供了更多更方便的函数
程序代码
1 | import math |