-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#write a series of random numbers to a file | ||
#numbers should be in the range of 1 - 500 | ||
#user should specify how many numbers the file will hold | ||
|
||
#set the filename as a global variable | ||
FILENAME = r'C:\Users\User\Desktop\python-projects\python_projects\random-number.txt' | ||
|
||
#i set the mode to append, so previous data will not be lost | ||
my_file = open(FILENAME, 'a') | ||
user_choice = int(input('how many numbers should be stored in the file?: ')) | ||
|
||
#create a list to hold the numbers entered by the user | ||
num_list = [] | ||
|
||
for num in range(0,user_choice): | ||
user_num = (input('write numbers between 1 and 500: ')) | ||
num_list.append(user_num) | ||
my_file.write(user_num + '\n') | ||
my_file.close() | ||
|
||
my_file = open(FILENAME, 'r') | ||
print('output') | ||
print(my_file.read()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
2 | ||
3 | ||
4 | ||
5 | ||
2 | ||
3 | ||
4 | ||
43 |