Vba Write Sub Figure Given User Supplied Integer N Many Prime Numbers Within 1 N List Shee Q37076487

VBA: Write a sub that can figure out, given a user-suppliedinteger n, how many prime numbers are there within 1 and n and willlist them on a sheet in an EXCEL workbook.


Solution


import xlwt
from xlwt import Workbook

def isPrime(num):
for i in range(2,num):
if(num%i == 0):
return False
return True

def excel_write(arr):
wb = Workbook()
sheet = wb.add_sheet(‘Sheet’)
sheet.write(0, 0, ‘Prime Numbers’)
for x in range(1,len(arr)):
sheet.write(x, 0, arr[x])
wb.save(‘prime.xls’)
print(‘Successfully saved in prime.xls’)

no = int(input(‘Input the Number : ‘))

prime_arr = []
for x in range(2,no):
if(isPrime(x)):
prime_arr.append(x)
excel_write(prime_arr)
  

CODEEXECUTION:RESTART: C:/Users/iamch/AppData/Local/Programs/Python/Python36-32/chegg_prime.p Input the Number 100 Successfully saved in pr

EXCEL SAVEDFILE:

1 Prime Numbers 2 3 4 3 13 17 19 23 6 8 9 10 29 31 37 41 43 47 53 59 61 67 71 73 79 83 12 13 14 15 16 17 18 19 89 97

RESTART:

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.