-
Notifications
You must be signed in to change notification settings - Fork 0
/
impor.txt
78 lines (61 loc) · 2.35 KB
/
impor.txt
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
import random
import string
def generate_password(length):
characters = string.ascii_letters + string.digits + string.punctuation
password = ''.join(random.choice(characters) for i in range(length))
return password
length = int(input("Enter desired password length: "))
password = generate_password(length)
print("Your generated password is:", password)import random
# Generate a random 10x10 grid filled with 0s and 1s
grid = [[random.choice([0, 1]) for _ in range(10)] for _ in range(10]
# Count the number of consecutive rows or columns with all 0s or all 1s
consecutive_count = 0
for i in range(10):
# Check rows
if all(grid[i][j] == 0 for j in range(10)) or all(grid[i][j] == 1 for j in range(10)):
consecutive_count += 1
# Check columns
if all(grid[j][i] == 0 for j in range(10)) or all(grid[j][i] == 1 for j in range(10)):
consecutive_count += 1
print("Number of consecutive rows or columns with all 0s or all 1s:", consecutive_count)import random
import string
def generate_password(length):
characters = string.ascii_letters + string.digits + string.punctuation
password = ''.join(random.choice(characters) for i in range(length))
return password
length = int(input("Enter the length of the password: "))
random_password = generate_password(length)
print("Random password:", random_password)import random
import string
def generate_password(length=15):
characters = string.ascii_letters + string.digits + string.punctuation
password = ''.join(random.choice(characters) for i in range(length))
return password
random_password = generate_password()
print(random_password)import statistics
def calculate_mean(numbers):
mean = sum(numbers) / len(numbers)
return mean
def calculate_median(numbers):
numbers.sort()
n = len(numbers)
if n % 2 == 0:
median = (numbers[n // 2 - 1] + numbers[n // 2]) / 2
else:
median = numbers[n // 2]
return median
def calculate_mode(numbers):
mode = max(set(numbers), key=numbers.count)
return mode
def main():
numbers = [1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8]
mean = calculate_mean(numbers)
median = calculate_median(numbers)
mode = calculate_mode(numbers)
print("List of numbers:", numbers)
print("Mean:", mean)
print("Median:", median)
print("Mode:", mode)
if __name__ == "__main__":
main()