-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaximum_integer.py
More file actions
34 lines (28 loc) · 843 Bytes
/
Copy pathmaximum_integer.py
File metadata and controls
34 lines (28 loc) · 843 Bytes
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
"""
This program will generate 100 random integers between 1 and 100
and display while also keeping track is the maximum number generated and
the number of times it was updated.
Input: None
Output: String of values
"""
import random
# Initialize state variables.
update_count = 0
largest = None
# Generate series of integers update the maximum value while keeping
# count on the number of updates.
for i in range(100):
num = random.randint(1, 100)
if largest is None:
largest = num
display = f'{num}'
elif largest < num:
largest = num
display = f"{num} <== Update"
update_count += 1
else:
display = f'{num}'
# Display all relevant information
print(display)
print(f'\nMaximum value found was {largest}')
print(f'Maximum value was updated {update_count} times')