-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment29.py
More file actions
142 lines (79 loc) · 2.6 KB
/
Copy pathassignment29.py
File metadata and controls
142 lines (79 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
1.
import random
def generate_divisible_by_5():
divisible_numbers = []
for _ in range(3):
number = random.randrange(100, 999, 5)
divisible_numbers.append(number)
return divisible_numbers
result = generate_divisible_by_5()
print("3 Random numbers divisible by 5:", result)
2.
import random
def lottery_tickets():
tickets = random.sample(range(1000000, 9999999), 100)
winners = random.sample(tickets, 2)
return tickets, winners
tickets, winners = lottery_tickets()
print("Lottery winners:", winners)
3.
import random
otp = random.randint(100000, 999999)
print("OTP:", otp)
4.
import random
input_string = "Hellgoodmorningsir"
random_char = random.choice(input_string)
print("Random Character:", random_char)
5.
import random
import string
characters = string.ascii_letters
random_characters = random.choices(characters, k=5)
random_string = ''.join(random_characters)
print("Random String:", random_string)
6.
import random
import string
def generate_password():
password_length = 10
password = [
random.choice(string.ascii_uppercase),
random.choice(string.ascii_uppercase),
random.choice(string.digits),
random.choice(string.punctuation)
]
password += random.choices(string.ascii_letters + string.digits + string.punctuation, k=password_length-4)
random.shuffle(password)
return ''.join(password)
password = generate_password()
print("Generated Password:", password)
7.
import random
num1 = random.uniform(1.0, 10.0)
num2 = random.uniform(1.0, 10.0)
result = num1 * num2
print("Multiplication Result:", result)
8.
import random
import string
import urllib.parse
secure_token = ''.join(random.choices(string.ascii_letters + string.digits, k=64))
base_url = "https://www.example.com/"
random_url = urllib.parse.urljoin(base_url, ''.join(random.choices(string.ascii_letters + string.digits, k=10)))
print("Secure Token:", secure_token)
print("Random URL:", random_url)
9.
import random
random.seed(42)
dice_roll = random.choice([1, 2, 3, 4, 5, 6])
print("Dice Roll (Same number):", dice_roll)
10.
import random
from datetime import datetime, timedelta
start_date = datetime(2020, 1, 1)
end_date = datetime(2025, 1, 1)
time_delta = end_date - start_date
random_days = random.randint(0, time_delta.days)
random_date = start_date + timedelta(days=random_days)
print("Random Date:", random_date.strftime("%Y-%m-%d"))