Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Mbaoma authored Jun 12, 2020
1 parent d429480 commit 30dba6f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 30daysofcode/random-number-writer/random-number-writer.py
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())
8 changes: 8 additions & 0 deletions 30daysofcode/random-number-writer/random-number.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
2
3
4
5
2
3
4
43

0 comments on commit 30dba6f

Please sign in to comment.