This simple isprime(number) function checks if the given integer number is a prime number and returns True or False. The function makes sure that the number is a positive integer, and that 1 is not considered a prime number. To find out if an integer n is odd one can use `n & 1`, to check for even one can then use `not n & 1` or the more traditional `n % 2 == 0` which is about 30% slower.

Member Avatar
Member Avatar
+2 forum 36

So I have this for a sound crew to select jobs for workers based on the training they have recieved. My code allows you to add workers to the list and set what jobs they are allowed to do through use of inputs. The second Function then randomly creates job assignments for people based on the parameters in the first function. I would like to be able to have people selected, with no repeats, and preferably without permanently deleting people from the lists, so that the lists can be saved permanently. With the current code i get the error ValueError: …

Member Avatar
Member Avatar
+0 forum 1

I have a python script which extracts unique ip addresses from snort log but how to modify or use regex to extract IPs only if they are logged more than 10 times per second? more specific: using "regex", if the second (i.e 41 in this scenario) doesn't change for more than 10 lines of having the same IP address then extract that IP. blacklist = list(open("/home/asad/blackdb/blacklist", 'r').read().split('\n')) logfile = list(open('/home/asad/logdb/snort.alert', 'r').read().split('\n')) newip = [] for entry in logfile: ips = re.findall(r'[0-9]+(?:\.[0-9]+){3}', entry) for ip in ips: newip.append(ip) newblist = blacklist + newip with open("/home/asad/blackdb/blacklist", 'w+') as f: f.write('\n' .join(set(newblist))+'\n\n') f.close() …

Member Avatar
Member Avatar
+0 forum 9

Login program

Member Avatar
Member Avatar
+0 forum 1

Below is a program that asks the user to input a username and password. Once logged off the user is asked to re-enter their username and password. Is the program correct where it checks if the username and password input before is correctly input again?. Any help would be welcome Regards Mark # program that checks that the username and password are correct # username = input("Please enter your username : ") password = input("Please enter your password : ") print ("Greetings," , username, "you are now logged in now with a password") command = input("Please type a command :") …

Member Avatar
Member Avatar
-1 forum 7

Design a function named max that accepts two integer values as arguments and returns the value that is greater? For example: if 7 and 12 are passed as arguments to the function, the function should return 12. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is greater of the two.

Member Avatar
Member Avatar
-1 forum 15

Hi all, I have 2 form and a main.py in the project: ffrend.py and fmain.py main.py: from PyQt4 import QtCore, QtGui from fmain import * if __name__ == "__main__": import sys app = QtGui.QApplication(sys.argv) MainWindow = QtGui.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() app.exec_() fmain.py (there is a button to execute the following function) def friendNetWork(self): form = QtGui.QWidget() ui = Ui_ffriend() ui.setupUi(form) form.show() app.exec_() When I run main.py, the fmain form is shown. When I click the button on fmain form, the friendNetWork will be executed and create another widget. But...I received the error in console :(...And the python is …

Member Avatar
Member Avatar
+0 forum 6

I was solving a problem related to the scheduling. The problem statement is as below:- We want to keep a three months workshop in the university in which all the students of the university will participate. All the students will be trained by the lecturers of their own university for two days in a month for a subject of his choice. And similarly he would get the training in the other two months for the other two subjects and all the students will study the three subjects in the complete three months workshop. The students needs to be divided into …

Member Avatar
+0 forum 0

Hi all, I am trying to get the code I have working with PsychoPy3. The code was written using python and psychopy2 and with PyQt4. Now I have PsychoPy3 and PyQt5. Apperantly getting things work with PyQt5 is not really straitforward. Anyway, I have accomplished some. Now, I have an error as below: Any idea how to solve this? experiment = Experiment(windowColor, markerNames, dataFromSubject, popupBetween, popupEnd, blocks, blockTextToDisplay, dbFile, dbTables, test, fileToUseToCalculateAverage = fileToUseToCalculateAverage) coordinates = MovieStimulusCoordinates(fileToUseToCalculateAverage['file'], fileToUseToCalculateAverage['numberOfDotsPerFrame'], fileToUseToCalculateAverage['matrixAlreadyNormalized']) self.__projectionMatrix = self.makeProjectionMatrix() return int(projectionMatrix.reshape(projectionMatrix.shape[0] / self.numberOfDotsPerFrame, self.numberOfDotsPerFrame, 2)) TypeError: 'float' object cannot be interpreted as an integer

Member Avatar
Member Avatar
+0 forum 1

## Intro ## Receiver Operating Characteristic (ROC) plots are useful for visualizing a predictive model’s effectiveness. This tutorial explains how to code ROC plots in Python from scratch. ## Data Preparation & Motivation ## We’re going to use the breast cancer dataset from sklearn’s sample datasets. It is an accessible, binary classification dataset (malignant vs. benign) with 30 positive, real-valued features. To train a logistic regression model, the dataset is split into train-test pools, then the model is fit to the training data. from sklearn.datasets import load_breast_cancer from sklearn.linear_model import * from sklearn.model_selection import train_test_split # Load datasetd dataset = …

Member Avatar
+3 forum 0

Hello. I wanted to download a "Python IDE" called "PyCharm" to type code using the coding language "Python" for class. Here is the problem: When I open up the IDE called "PyCharm", it says that the "Python Interpreter" is not found. I suspected it was because I downloaded the "IDE" before the "Interpreter" so I tried to configure it manually into the “IDE” after I downloaded “Python”. However, the “IDE” said that no permission was granted for the “Interpreter” to be used in this “IDE”. I downloaded a new version of this “IDE” and a more recent version of “Python”. …

Member Avatar
Member Avatar
+0 forum 4

Hi, I have a .csv file in an AWS machine i wanted to convert that .csv file to .dat file? Can you please help me? Thansk, Swetha. G

Member Avatar
Member Avatar
+0 forum 2

I can get the output with **data_2012['DeathRate ']** where there is a space after DeathRate but I can not get the same result without space after the DeathRate i.e, **data_2012['DeathRate']** in python.

Member Avatar
Member Avatar
+0 forum 1

As I continue my conversion from vbScript to Python I am finding the gotchas. For example... A lot of my utility scripts take a file name or a file pattern as a parameter. My script, bitrate.vbs, for example allows me to invoke it as bitrate file bitrate pattern Technically file and pattern are identical since specifying a file is really just specifying a pattern that matches up to one file. To get file listings in vbScript I would just spawn a dos `dir` command and grab the output from stdout. In Python, however, they provide what I thought was a …

Member Avatar
+2 forum 0

I need to extract the domain for example: (http: //www.example.com/example-page, http ://test.com/test-page) from a list of websites in an excel sheet and modify that domain to give its url (example.com, test.com). I have got the code part figured put but i still need to get these commands to work on excel sheet cells in a column automatically. >>> url = ("http://www.example.com") >>> domain = url.split("http://")[-1].split("/")[0] >>> print(domain) www.example.com >>> url_2 = ("http://example.com") >>> domain_2 = url_2.split("http://")[-1].split('/')[0] >>> print(domain_2) example.com >>> >>> #Now to remove www. from the first one >>> >>> domain_without_w3 = domain.split("www.")[-1] >>> print(domain_without_w3) example.com >>> >>> # …

Member Avatar
Member Avatar
+0 forum 2

The printer seems to be a much ignored computer peripheral when it comes to programming. This little code snippet explores one way to send text to the default printer. It actually draws the text into an imaginary box on the paper. You can specify the upper left and lower right corners of this box.

Member Avatar
Member Avatar
+2 forum 1

I've tried inurl:http but it takes forever to get even a bunch of sites right and I have to think of new keywords everytime to get the sites. Is there kind of a directory or a script i could use to filter the http from all the sites on the web. Or some sort of software?

Member Avatar
Member Avatar
+0 forum 5

I'm having a problem with my python installation. The packages that came with the installation work just fine but when I try to use other installed packages I run into problems. For example, I installed a package `pymsgbox` using pip from an admin shell. When I run a sample script from the command line as in `sample`, I get ModuleNotFoundError: No module named 'pymsgbox' but when I run it by `python sample.py` it works fine. Likewise if I load it into IDLE and run it from there. Suggestions?

Member Avatar
Member Avatar
+0 forum 8

Hi, I have to monitor outlook and trigger one code when ever new mail comes. Please help me.

Member Avatar
+0 forum 0

Have two CSV files containing client records and need to compare the two and then output to a third file those rows where there are differences to the values within the record (row) as well as output those records (rows) on the second file that are not on first file . Example: File 1: KeyField,Name,City, Zip,Location 123,Fred,Chicago,60558,A2 234,Mary,Orlando,12376,4L6 345,George,Pittsburgh,40567, 22 456,Peter,Topeka,00341,234 567,Doc,Birmingham,76543,H86 File 2: KeyField,Name,City,Zip,Location 123,Fred,Chicago,60558,A2 234,Mary,Orlando,12376,4L6 345,George,Boston, 40567,22 456,Peter,Topeka,00341,234 567,Doc,Birmingham,7654,H86 678,Isabel,Guadalajara,87654,M111 The results should create a file containing : 345,George,Boston,40567,22 678,Isabel,Guadalajara,87654,M111 The following code gets me in the neighborhood as a visual check: import os import difflib f=open('original.csv','r') #open …

Member Avatar
Member Avatar
+0 forum 10

Can someone explain me how can i check if an answer is right from question in files with python. In my files there are questions with three answers and among them one is the right one and the others are wrong. Users have to click on button to answer. Please help me.

Member Avatar
+0 forum 0

![Untitled.png](/attachments/large/4/b37cb01c4fe2e908e745a6af2e4a7975.png) hello i am currently working on a python program that remote controlls multiple computers at once, as if they were multiple screens of one computer. one of the features of this program, is that the server controlling all computers, builds a map from screens, and including its own - server screen. But when the server controlls its own screen, a recurtion effect starts, because it takes screenshots of the screenshots it show on the screen, and so on.. Here's the rough code of the screen capture i use (With PIL) def capture_screen(self): screen_contents = ImageGrab.grab() size = win_width, win_height …

Member Avatar
+0 forum 0

Hello guys, I need some help with a python program that i have to do for school. I don't know how to erase a button after using it. And how can i go to the next question after answering the first one. Please help me ASAP!

Member Avatar
Member Avatar
+0 forum 2

Hello, so im making an os in pydroid 3, but i cant make a clock, im trying to make a graphical os but i cant cause i need a clock, Any idea? And i edited someones code for username and password to work, but i had to delete raw_data or the program wont work, like, i enter a username and a password and it says wrong username/password entered, any help?

Member Avatar
+1 forum 0

Is NumPy is better than Python list?

Member Avatar
Member Avatar
+0 forum 3

Your goal is to write a Python function that takes a file handle as input and returns the most common words in the text file

Member Avatar
Member Avatar
+0 forum 2

I have to write a python program that get a keyboad number and verfiy using the def function. Help n = int(input("Write a number") def countdown(n): if n >= 0: print('Blast off! Zero down') else: print(n) countup(n+1) countdown(3)

Member Avatar
+0 forum 0

I have a bunch of variables as below.Now, I want to build a variable dynamically as below by iterating through for loop but surprisingly this won't work as .format can only be implemented for strings. Could anyone share your thoughts like how can this be implemented in Py? build_a="123" build_b="456" build_c="789" build_src = ['a','b','c'] build_list = {} for word in build_src: build_list[word] = build_{word}.format(word=word)

Member Avatar
Member Avatar
-1 forum 1

I am a fresher and want to learn Pandas (Python). A few professionals I talked to suggested I use the book "Learning Pandas" by Michael Heydt. Should I give it a try? Do you have any other suggestions for me?

Member Avatar
Member Avatar
+0 forum 1

If you press any key on your keyboard, this small Tkinter GUI program will tell you which key and what type of key has been pressed. Great for applications where a simple key stroke is required.

Member Avatar
Member Avatar
+1 forum 1

The End.