class 5

1.课前提问

  • python中基本数据类型有几种?分别是?
  • str()、int() 和 float()的作用分别是什么?
  • type() 函数的作用是什么?
  • 使用 int() 将小数转换为整数,结果是上取整还是下取整?
  • 除了 int() 不使用任何其他函数,如何对一个数四舍五入而不是下取整?(例如,13.2 会下取整为 13,但是 13.7 会上取整为 14。)

2.第五章内容——输入

2.1 input()

some_name=input()
print(some_name)
mark
print ("Enter your name: ")
somebody = input()
print ("Hi", somebody, "how are you today?")
Enter your name: 
Hi richie how are you today?

2.2 print 命令和逗号

somebody = input("Enter your name: ")
print ("Hi,", somebody, "how are you today?")
Hi, sss how are you today?

2.3 输入数字

a = 13.2
roundoff = int(a + 0.5)
print('a=',a,'b=',roundoff)
a= 13.2 b= 13
a=input()
roundoff = int(a + 0.5)
print('a=',a,'b=',roundoff)
---------------------------------------------------------------------------


TypeError                                 Traceback (most recent call last)


d:\Project\svn_test\BaiduNetdiskWorkspace\MM\CLASS\class5.ipynb Cell 7 in <cell line: 2>()


      <a href='vscode-notebook-cell:/d%3A/Project/svn_test/BaiduNetdiskWorkspace/MM/CLASS/class5.ipynb#ch0000016?line=0'>1</a> a=input()


----> <a href='vscode-notebook-cell:/d%3A/Project/svn_test/BaiduNetdiskWorkspace/MM/CLASS/class5.ipynb#ch0000016?line=1'>2</a> roundoff = int(a + 0.5)


      <a href='vscode-notebook-cell:/d%3A/Project/svn_test/BaiduNetdiskWorkspace/MM/CLASS/class5.ipynb#ch0000016?line=2'>3</a> print('a=',a,'b=',roundoff)





TypeError: can only concatenate str (not "float") to str

2.4 来自互联网的输入

import pandas as pd
dfs = pd.read_html('https://funddb.cn/site/index')
dfs[1]
0 1 2 3 4 5 6 7 8
0 全指通信000994.CSI 18.26 0.04% 1.42 0.29% 1.61 99.30% -21.42% 查看详情
1 德国DAXGDAXI.GI 11.42 0.08% 1.43 6.53% 3.61 96.05% -19.34% 查看详情
2 澳洲标普200AS51.GI 15.00 0.68% 1.98 36.44% 5.06 92.99% -11.11% 查看详情
3 380价值000118.SH 8.34 0.75% 1.00 1.99% 4.10 99.42% 1.05% 查看详情
4 医疗器械h30217.CSI 21.61 0.87% 5.45 29.38% 1.15 98.99% -14.73% 查看详情
... ... ... ... ... ... ... ... ... ...
153 中证全指电力指数h30199.CSI 66.88 98.93% 1.93 87.36% 1.99 4.72% -9.23% 查看详情
154 汽车(申万)801880.SI 35.53 99.5% 2.47 72.96% 1.38 30.48% -4.30% 查看详情
155 全指消费000990.CSI 75.53 99.92% 6.92 88.04% 1.24 33.69% -4.93% 查看详情
156 全指公用000995.CSI 49.33 100% 1.94 87.35% 2.06 16.18% -9.29% 查看详情
157 农林牧渔(申万)801010.SI 131.47 100% 3.74 67.84% 0.44 11.30% 2.26% 查看详情

158 rows × 9 columns

2.5 你学到了什么

2.6 测试题

  1. 如果用户键入 12,answer 的数据类型是什么?是字符串还是一个数?

  2. 怎么让 raw_input() 打印一个提示消息?

  3. 怎么使用 raw_input() 得到一个整数?

  4. 怎么使用 raw_input() 得到一个浮点数(小数)?

2.7 动手试一试

  1. 在交互模式中建立两个变量,分别表示你的姓和名。然后使用一条 print 语句,把姓和名打印在一起。

  2. 编写一个程序,先问你的姓,再问名,然后打印一条消息,在消息中包含你的姓和名。

  3. 编写一个程序询问一间长方形房间的尺寸(单位是米),然后计算覆盖整个房间总共需要多少地毯,并显示出来。

  4. 编写一个程序先完成第 3 题的要求,不过还要询问每平方尺地毯的价格。然后主程序显示下面 3 个内容:

总共需要多少地毯,单位是平方米。

总共需要多少地毯,单位是平方尺(1 平方米 = 9 平方尺)。

地毯总价格。

  1. 编写一个程序帮助用户统计她的零钱。程序要问下面的问题。

“有多少个五分币?”

“有多少个二分币?”

“有多少个一分币?”

让程序给出这些零钱的总面值

# no 2
last_name=input('please input your family name:')
first_name = input('please input your first name:')
print(last_name+first_name)
liuruichao

3.游戏环节


本文章使用limfx的vscode插件快速发布