|
17 | 17 | }, |
18 | 18 | { |
19 | 19 | "cell_type": "code", |
20 | | - "execution_count": 7, |
| 20 | + "execution_count": 3, |
21 | 21 | "metadata": {}, |
22 | 22 | "outputs": [ |
23 | 23 | { |
24 | 24 | "name": "stdout", |
25 | 25 | "output_type": "stream", |
26 | 26 | "text": [ |
27 | | - "Input your age (use only whole numbers): 23\n", |
28 | 27 | "Age's first type is: <class 'int'>\n", |
29 | 28 | "Age's second type is: <class 'int'>\n", |
30 | | - "In ten years you will be 33.\n" |
| 29 | + "It is good to be 11.\n" |
31 | 30 | ] |
32 | 31 | } |
33 | 32 | ], |
|
51 | 50 | }, |
52 | 51 | { |
53 | 52 | "cell_type": "code", |
54 | | - "execution_count": null, |
| 53 | + "execution_count": 9, |
55 | 54 | "metadata": { |
56 | 55 | "collapsed": true |
57 | 56 | }, |
58 | | - "outputs": [], |
| 57 | + "outputs": [ |
| 58 | + { |
| 59 | + "name": "stdout", |
| 60 | + "output_type": "stream", |
| 61 | + "text": [ |
| 62 | + "only int is accepted\n" |
| 63 | + ] |
| 64 | + } |
| 65 | + ], |
59 | 66 | "source": [ |
60 | 67 | "# [ ] input a number \n", |
| 68 | + "num_1= input(\"Enter an integer value\")\n", |
61 | 69 | "# if number IS a digit string then cast to int\n", |
62 | | - "# print number \"greater than 100 is\" True/False\n", |
63 | | - "# if number is NOT a digit string then message the user that \"only int is accepted\"\n", |
| 70 | + "if num_1.isdigit() :\n", |
| 71 | + " num_1 = int(num_1)\n", |
| 72 | + " # print number \"greater than 100 is\" True/False\n", |
| 73 | + " print(\"greater than 100 is\" , num_1 > 100)\n", |
| 74 | + "else :\n", |
| 75 | + " # if number is NOT a digit string then message the user that \"only int is accepted\"\n", |
| 76 | + " print(\"only int is accepted\")\n", |
| 77 | + "\n", |
| 78 | + "\n", |
64 | 79 | "\n", |
65 | 80 | "\n" |
66 | 81 | ] |
|
262 | 277 | }, |
263 | 278 | { |
264 | 279 | "cell_type": "code", |
265 | | - "execution_count": null, |
| 280 | + "execution_count": 10, |
266 | 281 | "metadata": {}, |
267 | | - "outputs": [], |
| 282 | + "outputs": [ |
| 283 | + { |
| 284 | + "name": "stdout", |
| 285 | + "output_type": "stream", |
| 286 | + "text": [ |
| 287 | + "4\n" |
| 288 | + ] |
| 289 | + } |
| 290 | + ], |
268 | 291 | "source": [ |
269 | 292 | "# [ ] add 2 numbers from input using a cast to integer and display the answer \n", |
270 | | - "\n" |
| 293 | + "\n", |
| 294 | + "num_1 = input(\"enter 2 integers\")\n", |
| 295 | + "num_2 = input(\"enter 2 integers\")\n", |
| 296 | + "num_3 = int(num_1) + int(num_2)\n", |
| 297 | + "print(num_3)" |
271 | 298 | ] |
272 | 299 | }, |
273 | 300 | { |
274 | 301 | "cell_type": "code", |
275 | | - "execution_count": null, |
| 302 | + "execution_count": 11, |
276 | 303 | "metadata": {}, |
277 | | - "outputs": [], |
| 304 | + "outputs": [ |
| 305 | + { |
| 306 | + "name": "stdout", |
| 307 | + "output_type": "stream", |
| 308 | + "text": [ |
| 309 | + "the answer is... 16\n" |
| 310 | + ] |
| 311 | + } |
| 312 | + ], |
278 | 313 | "source": [ |
279 | 314 | "# [ ] Multiply 2 numbers from input using cast and save the answer as part of a string \"the answer is...\"\n", |
280 | 315 | "# display the string using print\n", |
281 | | - "\n" |
| 316 | + "num_1 = input(\"enter 2 integers\")\n", |
| 317 | + "num_2 = input(\"enter 2 integers\")\n", |
| 318 | + "num_3 = int(num_1) * int(num_2)\n", |
| 319 | + "print(\"the answer is...\", num_3)\n" |
282 | 320 | ] |
283 | 321 | }, |
284 | 322 | { |
285 | 323 | "cell_type": "code", |
286 | | - "execution_count": null, |
| 324 | + "execution_count": 13, |
287 | 325 | "metadata": {}, |
288 | | - "outputs": [], |
| 326 | + "outputs": [ |
| 327 | + { |
| 328 | + "name": "stdout", |
| 329 | + "output_type": "stream", |
| 330 | + "text": [ |
| 331 | + "2.0\n" |
| 332 | + ] |
| 333 | + } |
| 334 | + ], |
289 | 335 | "source": [ |
290 | 336 | "# [ ] get input of 2 numbers and display the average: (num1 + num2) divided by 2\n", |
291 | | - "\n" |
| 337 | + "num_1 = input(\"enter 2 integers\")\n", |
| 338 | + "num_2 = input(\"enter 2 integers\")\n", |
| 339 | + "num_3 = (int(num_1) + int(num_2)) / 2\n", |
| 340 | + "print(num_3)" |
292 | 341 | ] |
293 | 342 | }, |
294 | 343 | { |
295 | 344 | "cell_type": "code", |
296 | | - "execution_count": null, |
| 345 | + "execution_count": 15, |
297 | 346 | "metadata": {}, |
298 | | - "outputs": [], |
| 347 | + "outputs": [ |
| 348 | + { |
| 349 | + "name": "stdout", |
| 350 | + "output_type": "stream", |
| 351 | + "text": [ |
| 352 | + "2\n" |
| 353 | + ] |
| 354 | + } |
| 355 | + ], |
299 | 356 | "source": [ |
300 | 357 | "# [ ] get input of 2 numbers and subtract the largest from the smallest (use an if statement to see which is larger)\n", |
301 | 358 | "# show the answer\n", |
| 359 | + "num_1 = input(\"enter 2 integers\")\n", |
| 360 | + "num_2 = input(\"enter 2 integers\")\n", |
| 361 | + "if num_1 > num_2 :\n", |
| 362 | + " num_3 = int(num_1) - int(num_2)\n", |
| 363 | + " print(num_3)\n", |
| 364 | + "elif num_1 < num_2 :\n", |
| 365 | + " num_3 = int(num_2) - int(num_1)\n", |
| 366 | + " print(num_3)\n", |
| 367 | + "elif num_1 == num_2 :\n", |
| 368 | + " num_3 = int(num_2) - int(num_1)\n", |
| 369 | + " print(num_3)\n", |
| 370 | + "else :\n", |
| 371 | + " print(\"invalid input\")\n", |
302 | 372 | "\n" |
303 | 373 | ] |
304 | 374 | }, |
305 | 375 | { |
306 | 376 | "cell_type": "code", |
307 | | - "execution_count": null, |
| 377 | + "execution_count": 38, |
308 | 378 | "metadata": {}, |
309 | | - "outputs": [], |
| 379 | + "outputs": [ |
| 380 | + { |
| 381 | + "name": "stdout", |
| 382 | + "output_type": "stream", |
| 383 | + "text": [ |
| 384 | + "5\n" |
| 385 | + ] |
| 386 | + } |
| 387 | + ], |
310 | 388 | "source": [ |
311 | 389 | "# [ ] Divide a larger number by a smaller number and print the integer part of the result\n", |
312 | 390 | "# don't divide by zero! if a zero is input make the result zero\n", |
313 | 391 | "# [ ] cast the answer to an integer to cut off the decimals and print the result\n", |
314 | | - "\n" |
| 392 | + "\n", |
| 393 | + "#get user input\n", |
| 394 | + "num_1 = input(\"enter 2 integers\")\n", |
| 395 | + "num_2 = input(\"enter 2 integers\")\n", |
| 396 | + "#change to int so or statement works properly\n", |
| 397 | + "num_1 = int(num_1)\n", |
| 398 | + "num_2 = int(num_2)\n", |
| 399 | + "#divide by 0 check\n", |
| 400 | + "if num_1 == 0 or num_2 == 0 :\n", |
| 401 | + " print(\"0\")\n", |
| 402 | + "\n", |
| 403 | + "elif num_1 > num_2 :\n", |
| 404 | + " num_3 = int(num_1) / int(num_2)\n", |
| 405 | + " num_3 = int(num_3)\n", |
| 406 | + " print(num_3)\n", |
| 407 | + "elif num_1 < num_2 :\n", |
| 408 | + " num_3 = int(num_2) / int(num_1)\n", |
| 409 | + " num_3 = int(num_3)\n", |
| 410 | + " print(num_3)\n", |
| 411 | + "#int check\n", |
| 412 | + "else :\n", |
| 413 | + " print(\"invalid input\")\n" |
315 | 414 | ] |
316 | 415 | }, |
317 | 416 | { |
|
327 | 426 | "metadata": { |
328 | 427 | "anaconda-cloud": {}, |
329 | 428 | "kernelspec": { |
330 | | - "display_name": "Python 3", |
| 429 | + "display_name": "Python 3.9.12 ('base')", |
331 | 430 | "language": "python", |
332 | 431 | "name": "python3" |
333 | 432 | }, |
|
341 | 440 | "name": "python", |
342 | 441 | "nbconvert_exporter": "python", |
343 | 442 | "pygments_lexer": "ipython3", |
344 | | - "version": "3.8.8" |
| 443 | + "version": "3.9.12" |
| 444 | + }, |
| 445 | + "vscode": { |
| 446 | + "interpreter": { |
| 447 | + "hash": "5c63ba0b8f8ad222cc0b06bdcd9f04f10ed843d7f084a2f46bb405b77fc04261" |
| 448 | + } |
345 | 449 | } |
346 | 450 | }, |
347 | 451 | "nbformat": 4, |
|
0 commit comments