#ensures that the main program only runs when the functions have not been imported into another file. Why? # returns all integers from 2 to a limit given by the user. As the line with range is not a list I fixed it only to improve the code, but when I changed the name of the value from 'lista' to another name, I saw that it doesn't work too. It runs as I expected, but when I tried deleting the first list assignment line and include the range function directly into the comprehension, it doesn't work. #Ensures that the main program only runs when the functions have not been imported into another file. #call the function which selects the numbers and returns the result. #filters the prime numbers and places in a list. In this video, we will learn how to generate a List of Prime Numbers from 1 to 100 in Python. I wrote this code: # returns all integers from 2 to a limit given by the user. Prime numbers are numbers that cannot be divisible by 2, 3 or 7, excluding 2, 3 or 7 With this knowledge I adapted your code to show the true prime. I found that the variable i is always equal to 2 in your code.This destroys the purpose of having a second for loop. I was trying to reduce the maximum amount of lines I could and was surprised with some situations I can't understand. I am assuming the random number is the range you want the numbers to be within. The user gives a limit and the program displays all prime number from 2 to the limit. I was trying to write a code to select the prime numbers in a list.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |