Skip to content

Commit 1ceefb5

Browse files
Random Module
1 parent 85022fc commit 1ceefb5

File tree

1 file changed

+176
-2
lines changed

1 file changed

+176
-2
lines changed

PythonFromScratch.ipynb

+176-2
Original file line numberDiff line numberDiff line change
@@ -2372,7 +2372,7 @@
23722372
},
23732373
{
23742374
"cell_type": "code",
2375-
"execution_count": 8,
2375+
"execution_count": 1,
23762376
"metadata": {},
23772377
"outputs": [],
23782378
"source": [
@@ -2460,6 +2460,26 @@
24602460
"isfile(os.getcwd())"
24612461
]
24622462
},
2463+
{
2464+
"cell_type": "code",
2465+
"execution_count": 2,
2466+
"metadata": {},
2467+
"outputs": [
2468+
{
2469+
"data": {
2470+
"text/plain": [
2471+
"'c:/Users/Anas'"
2472+
]
2473+
},
2474+
"execution_count": 2,
2475+
"metadata": {},
2476+
"output_type": "execute_result"
2477+
}
2478+
],
2479+
"source": [
2480+
"join(\"c:/\", 'Users/Anas')"
2481+
]
2482+
},
24632483
{
24642484
"cell_type": "code",
24652485
"execution_count": 13,
@@ -2499,7 +2519,7 @@
24992519
},
25002520
{
25012521
"cell_type": "code",
2502-
"execution_count": 23,
2522+
"execution_count": 3,
25032523
"metadata": {},
25042524
"outputs": [
25052525
{
@@ -2535,6 +2555,160 @@
25352555
"normpath(join(r\"c://\\Users//Anas//\\/\\\\//Videos//YOUTUBE//imgs//Python//Tutorial\", 'text.txt'))"
25362556
]
25372557
},
2558+
{
2559+
"cell_type": "markdown",
2560+
"metadata": {},
2561+
"source": [
2562+
"# Random Module"
2563+
]
2564+
},
2565+
{
2566+
"cell_type": "code",
2567+
"execution_count": 1,
2568+
"metadata": {},
2569+
"outputs": [],
2570+
"source": [
2571+
"import random as rand"
2572+
]
2573+
},
2574+
{
2575+
"cell_type": "code",
2576+
"execution_count": 8,
2577+
"metadata": {},
2578+
"outputs": [
2579+
{
2580+
"data": {
2581+
"text/plain": [
2582+
"5"
2583+
]
2584+
},
2585+
"execution_count": 8,
2586+
"metadata": {},
2587+
"output_type": "execute_result"
2588+
}
2589+
],
2590+
"source": [
2591+
"rand.randrange(1,6)"
2592+
]
2593+
},
2594+
{
2595+
"cell_type": "code",
2596+
"execution_count": 9,
2597+
"metadata": {},
2598+
"outputs": [],
2599+
"source": [
2600+
"lt = ['a', 'b', 'c', 'd', 'e']"
2601+
]
2602+
},
2603+
{
2604+
"cell_type": "code",
2605+
"execution_count": 13,
2606+
"metadata": {},
2607+
"outputs": [
2608+
{
2609+
"data": {
2610+
"text/plain": [
2611+
"'b'"
2612+
]
2613+
},
2614+
"execution_count": 13,
2615+
"metadata": {},
2616+
"output_type": "execute_result"
2617+
}
2618+
],
2619+
"source": [
2620+
"rand.choice(lt)"
2621+
]
2622+
},
2623+
{
2624+
"cell_type": "code",
2625+
"execution_count": 17,
2626+
"metadata": {},
2627+
"outputs": [
2628+
{
2629+
"data": {
2630+
"text/plain": [
2631+
"0.36124031046585225"
2632+
]
2633+
},
2634+
"execution_count": 17,
2635+
"metadata": {},
2636+
"output_type": "execute_result"
2637+
}
2638+
],
2639+
"source": [
2640+
"rand.random()"
2641+
]
2642+
},
2643+
{
2644+
"cell_type": "code",
2645+
"execution_count": 19,
2646+
"metadata": {},
2647+
"outputs": [
2648+
{
2649+
"data": {
2650+
"text/plain": [
2651+
"['d', 'e', 'b']"
2652+
]
2653+
},
2654+
"execution_count": 19,
2655+
"metadata": {},
2656+
"output_type": "execute_result"
2657+
}
2658+
],
2659+
"source": [
2660+
"rand.sample(lt, 3)"
2661+
]
2662+
},
2663+
{
2664+
"cell_type": "code",
2665+
"execution_count": 22,
2666+
"metadata": {},
2667+
"outputs": [],
2668+
"source": [
2669+
"rand.shuffle(lt)"
2670+
]
2671+
},
2672+
{
2673+
"cell_type": "code",
2674+
"execution_count": 23,
2675+
"metadata": {},
2676+
"outputs": [
2677+
{
2678+
"data": {
2679+
"text/plain": [
2680+
"['c', 'a', 'e', 'd', 'b']"
2681+
]
2682+
},
2683+
"execution_count": 23,
2684+
"metadata": {},
2685+
"output_type": "execute_result"
2686+
}
2687+
],
2688+
"source": [
2689+
"lt"
2690+
]
2691+
},
2692+
{
2693+
"cell_type": "code",
2694+
"execution_count": 40,
2695+
"metadata": {},
2696+
"outputs": [
2697+
{
2698+
"data": {
2699+
"text/plain": [
2700+
"5"
2701+
]
2702+
},
2703+
"execution_count": 40,
2704+
"metadata": {},
2705+
"output_type": "execute_result"
2706+
}
2707+
],
2708+
"source": [
2709+
"rand.randint(3,7)"
2710+
]
2711+
},
25382712
{
25392713
"cell_type": "code",
25402714
"execution_count": null,

0 commit comments

Comments
 (0)