I am having a really tough time trying to add an an exception that will not allow users to input 0 and negative numbers. Can someone please point me in the right direction?
The Program writes random values according to the user's input of how many random variables they want.
Here is what I have so far:
import random
rand_write= open("randomnum.txt", "w")
while(True):
try:
for i in range(int(input('How many random numbers would you like to generate?: '))):
line = str(random.randint(1,999)) +"\n"
rand_write.write(line)
print(line)
except ValueError:
print()
print('PLEASE ENTER NUMERICAL VALUE ONLY')
print()
else:
break
rand_write.close()
This post has been edited by Atli: 19 September 2016 - 09:50 PM
Reason for edit:: Fixed the code tags.

New Topic/Question
Reply


MultiQuote





|