Skip to content

Commit 81be8f2

Browse files
author
zhangmingming
authored
Merge pull request #5 from liupengyuan/master
update
2 parents e81db93 + f8a324b commit 81be8f2

104 files changed

Lines changed: 54806 additions & 186 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

201611680330.ipynb

Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {
7+
"collapsed": false,
8+
"deletable": true,
9+
"editable": true
10+
},
11+
"outputs": [
12+
{
13+
"name": "stdout",
14+
"output_type": "stream",
15+
"text": [
16+
"please input an int\n",
17+
"3\n",
18+
"please input the min\n",
19+
"1\n",
20+
"please input the max\n",
21+
"5\n",
22+
"均值是 2.6666666666666665\n",
23+
"平方根 1.632993161855452\n"
24+
]
25+
}
26+
],
27+
"source": [
28+
"print('please input an int')\n",
29+
"n=int(input())\n",
30+
"print('please input the min')\n",
31+
"m=int(input())\n",
32+
"print('please input the max')\n",
33+
"k=int(input())\n",
34+
"i=1\n",
35+
"total=0\n",
36+
"while i<=n:\n",
37+
" import random\n",
38+
" number=random.randint(m,k)\n",
39+
" total=total+number\n",
40+
" i=i+1\n",
41+
"jun=total/n\n",
42+
"print('均值是',jun)\n",
43+
"import math\n",
44+
"print('平方根',math.sqrt(jun))\n",
45+
" "
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": 1,
51+
"metadata": {
52+
"collapsed": false,
53+
"deletable": true,
54+
"editable": true
55+
},
56+
"outputs": [
57+
{
58+
"name": "stdout",
59+
"output_type": "stream",
60+
"text": [
61+
"the number you need\n",
62+
"2\n",
63+
"the min\n",
64+
"8\n",
65+
"the max\n",
66+
"12\n",
67+
"6.339850002884624\n",
68+
"0.6309297535714575\n"
69+
]
70+
}
71+
],
72+
"source": [
73+
"#写函数,共n个随机整数,整数范围在m与k之间,求西格玛log(随机整数)及西格玛1/log(随机整数)\n",
74+
"print('the number you need')\n",
75+
"n=int(input())\n",
76+
"print('the min')\n",
77+
"m=int(input())\n",
78+
"print('the max')\n",
79+
"k=int(input())\n",
80+
"i=1\n",
81+
"total1=0\n",
82+
"total2=0\n",
83+
"while i<=n:\n",
84+
" import random\n",
85+
" import math\n",
86+
" c=random.randint(m,k)\n",
87+
" c1=math.log2(c)\n",
88+
" c2=1/c1\n",
89+
" total1=total1+c1\n",
90+
" total2=total2+c2\n",
91+
" i+=1\n",
92+
"print(total1)\n",
93+
"print(total2)\n",
94+
" \n",
95+
" "
96+
]
97+
},
98+
{
99+
"cell_type": "code",
100+
"execution_count": 11,
101+
"metadata": {
102+
"collapsed": false,
103+
"deletable": true,
104+
"editable": true
105+
},
106+
"outputs": [
107+
{
108+
"name": "stdout",
109+
"output_type": "stream",
110+
"text": [
111+
"the number you need\n",
112+
"3\n",
113+
"1\n",
114+
"123\n"
115+
]
116+
}
117+
],
118+
"source": [
119+
"#写函数,求s=a+aa+aaa+aaaa+aa...a的值,其中a是[1,9]之间的随机整数。例如2+22+222+2222+22222(此时共有5个数相加),几个数相加由键盘输入。\n",
120+
"print('the number you need')\n",
121+
"n=int(input())\n",
122+
"import random\n",
123+
"a=random.randint(1,9)\n",
124+
"print(a)\n",
125+
"i=1\n",
126+
"total=0\n",
127+
"a1=a\n",
128+
"while i<n:\n",
129+
" a1=a+a1*10\n",
130+
" total=total+a1\n",
131+
" i+=1\n",
132+
"print(total+a)\n",
133+
" "
134+
]
135+
},
136+
{
137+
"cell_type": "code",
138+
"execution_count": 14,
139+
"metadata": {
140+
"collapsed": false,
141+
"deletable": true,
142+
"editable": true
143+
},
144+
"outputs": [
145+
{
146+
"name": "stdout",
147+
"output_type": "stream",
148+
"text": [
149+
"现在让电脑在100~1000见选定一个数作为神秘整数的上界\n",
150+
"上界是 771\n",
151+
"请输入想让电脑猜的数字\n",
152+
"500\n",
153+
"电脑第 1 次猜的数是 701\n",
154+
"一共可以猜 9 次\n",
155+
"已经猜了 1 次\n",
156+
"抱歉,你猜大了\n",
157+
"电脑第 2 次猜的数是 26\n",
158+
"一共可以猜 9 次\n",
159+
"已经猜了 2 次\n",
160+
"抱歉,你猜小了\n",
161+
"电脑第 3 次猜的数是 256\n",
162+
"一共可以猜 9 次\n",
163+
"已经猜了 3 次\n",
164+
"抱歉,你猜小了\n",
165+
"电脑第 4 次猜的数是 340\n",
166+
"一共可以猜 9 次\n",
167+
"已经猜了 4 次\n",
168+
"抱歉,你猜小了\n",
169+
"电脑第 5 次猜的数是 511\n",
170+
"一共可以猜 9 次\n",
171+
"已经猜了 5 次\n",
172+
"抱歉,你猜大了\n",
173+
"电脑第 6 次猜的数是 584\n",
174+
"一共可以猜 9 次\n",
175+
"已经猜了 6 次\n",
176+
"抱歉,你猜大了\n",
177+
"电脑第 7 次猜的数是 690\n",
178+
"一共可以猜 9 次\n",
179+
"已经猜了 7 次\n",
180+
"抱歉,你猜大了\n",
181+
"电脑第 8 次猜的数是 44\n",
182+
"一共可以猜 9 次\n",
183+
"已经猜了 8 次\n",
184+
"抱歉,你猜小了\n",
185+
"电脑第 9 次猜的数是 325\n",
186+
"一共可以猜 9 次\n",
187+
"已经猜了 9 次\n",
188+
"抱歉,你猜小了\n",
189+
"哈哈哈,电脑你输了\n"
190+
]
191+
}
192+
],
193+
"source": [
194+
"#挑战性练习:将猜数游戏改成由用户随便选择一个整数,让计算机来猜测的猜数游戏。\n",
195+
"def guessgame():\n",
196+
" import random,math\n",
197+
" print('现在让电脑在100~1000见选定一个数作为神秘整数的上界')\n",
198+
" n1 = random.randint(100,1000)\n",
199+
" print('上界是',n1)\n",
200+
" print('请输入想让电脑猜的数字')\n",
201+
" n2 = int(input())\n",
202+
" maxtimes = math.ceil(math.log(n2, 2))\n",
203+
" guesstimes = 0\n",
204+
" \n",
205+
" while guesstimes < maxtimes:\n",
206+
" guess = random.randint(0,n1)\n",
207+
" print('电脑第',guesstimes+1,'次猜的数是',guess)\n",
208+
" guesstimes += 1\n",
209+
" print('一共可以猜', maxtimes, '次')\n",
210+
" print('已经猜了', guesstimes, '次')\n",
211+
" \n",
212+
" if guess == n2:\n",
213+
" win()\n",
214+
" print('神秘数字是:', guess)\n",
215+
" print('你比标准次数少', maxtimes-guesstimes, '次')\n",
216+
" break \n",
217+
" elif guess>n2:\n",
218+
" print('抱歉,你猜大了')\n",
219+
" else:\n",
220+
" print('抱歉,你猜小了')\n",
221+
" print('哈哈哈,电脑你输了')\n",
222+
"guessgame()\n",
223+
" "
224+
]
225+
},
226+
{
227+
"cell_type": "code",
228+
"execution_count": null,
229+
"metadata": {
230+
"collapsed": true,
231+
"deletable": true,
232+
"editable": true
233+
},
234+
"outputs": [],
235+
"source": []
236+
}
237+
],
238+
"metadata": {
239+
"kernelspec": {
240+
"display_name": "Python 3",
241+
"language": "python",
242+
"name": "python3"
243+
},
244+
"language_info": {
245+
"codemirror_mode": {
246+
"name": "ipython",
247+
"version": 3
248+
},
249+
"file_extension": ".py",
250+
"mimetype": "text/x-python",
251+
"name": "python",
252+
"nbconvert_exporter": "python",
253+
"pygments_lexer": "ipython3",
254+
"version": "3.6.0"
255+
}
256+
},
257+
"nbformat": 4,
258+
"nbformat_minor": 2
259+
}

0 commit comments

Comments
 (0)