What is Python: Definition and 655 Discussions

PYTHON was a Cold War contingency plan of the British Government for the continuity of government in the event of nuclear war.

View More On Wikipedia.org
  1. M

    Python: Semidefinite program with CVXPy 'Error parsing inputs'

    Hi, Question: Why is the error 'Error parsing inputs' in CVXPy occurring? Context: I am trying to solve a semidefinite program in CVXPy (using Google Colab). I went to the documentation (HERE) and I copied the example code into a cell. It doesn't work for some reason and I don't understand...
  2. ergospherical

    Algorithmic trading with python

    If you have used an online course pertaining to the title, could you write a short review? Not looking for a book.
  3. M

    Import python list from .txt file into Mathematica

    Hi PF! I am trying to import k.txt file into Mathematica as a list of numbers. The k.txt looks like this: [5.315967917338153e-06, -3.204321972222162e-08, 3.6041782425371564e-09, -3.853442465663655e-08, 8.699510604529962e-07, -1.4284341965847237e-08, 2.855341882658808e-09...
  4. user366312

    Polymer simulation source code in C++ and Python

    I am absolutely new to Polymer simulation. I am trying to understand the simulation by analyzing source code written by others. Can anyone tell me what are the differences between the following three source code in terms of their objectives? Monte-Carlo-simulation-of-polymers...
  5. F

    Python "ImportError: bad magic number ...."

    # Test suite for Problem Set 3 (Simulating Robots) # Fall 2016 import sys import threading import traceback import unittest import random import imp test = imp.load_compiled("test", "test.pyc") import ps3 def xyrange(x_upper_bound, y_upper_bound): """ Returns the cartesian product of...
  6. bikashdaga

    Static variable in static method - how to use?

    I wanted to declare a local variable inside a static method main(). My code looks like this - class Operator { static int a; public static void input() { Scanner in=new Scanner(System.in); System.out.println("Enter the number:"); a=in.nextInt(); //this is...
  7. R

    I am trying to use alembic in python flask and it is not working

    https://blog.miguelgrinberg.com/post/how-to-add-flask-migrate-to-an-existing-project I am using Visual Studio Code and have a database file already created called test.db. My environment variables for test.db name is SQLALCHEMY_DATABASE_URI and the value is sqlite:///test.db In the actual code...
  8. M

    Use Python to integrate a function constructed in Mathematica

    Hi PF! I followed someone's help on here and have the following code in python that performs monte carlo integration from math import * from random import * def integrate(alpha): # MONTE CARLO INTEGRATION OVER NON-RECTANGULAR DOMAINS def f(pt): # RETURN INTEGRAND AS FUNCTION...
  9. R

    TemplateSyntaxError in Python Flask

    This is in python flask. I am getting an error line 16, in template <h2> <a href="{{ url_for('userinfo.profile', username=current_user.username, 'update_profile') }}"> update_profile_info </a> </h2> jinja2.exceptions.TemplateSyntaxError: invalid syntax for function call expression The...
  10. A

    Image comparison software (similarity and differences)

    Images comparison What are the best softwares available for comparing two images having similarity and differences? Two photos each of Margaret and Enid. 1 Margaret's first photo with her second photo comparison. 2 Enid's first photo with her second photo comparision. 3 Margaret's first...
  11. M

    Python code returning "none"

    Hi PF! I'm trying to write a code that, given a list of integers, will output the next lexicographic permutation. But my output gives me None, and I can't see why. Is it because I am incorrectly calling the reverse function? Any help is greatly appreciated! class Solution(object): def...
  12. B

    Python Input error for LSTM neural network

    Hi everyone, I have to classify a DNA sequence with a LSTM neural network but I have a problem with the inputs shame. Both the sequence and the class are encoded with One Hot Encoding and my code is this: import pandas as pd import numpy as np data = pd.read_csv('splice.data', header = None)...
  13. B

    How to make progress in programming classes?

    Hi everyone, Hopefully I'm writing this in the correct part of PhysicsForum. Here is my problem: I'm really struggling with my programming class (basics of python3 - loops, dictionaries, numpy). What I did this semester: 1. Participated in every class 2. Solved everything our course offered...
  14. shivajikobardan

    How to implement this pseudocode in python?

    What are the things that I need to know in order to implement this pseudocode in python?
  15. M

    Python header question from leetcode solution

    Hi PF! I am looking at the following code class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def removeNthFromEnd(head: ListNode, n: int) -> ListNode: # Two pointers - fast and slow slow = head fast = head # Move fast...
  16. M

    Executing Specific Python Lines in VS Code on Ubuntu

    Hi PF! I am running VS Code for python on Ubuntu. Is there a way to execute a specific python line? As I currently have it set up, on the terminal input at the bottom of the screen, I can only work through the terminal, so a command like print('hello world') won't do anything. THanks so mcuh!
  17. M

    Why is spaces equal to tree_height-1 in the Christmas tree code in Python?

    Hey! :giggle: I found online the following code for a christmas tree in Python : tree_height = input("Enter the tree height : ") tree_height = int(tree_height) spaces = tree_height-1 hashes = 1 stump_spaces = tree_height-1 while tree_height != 0 : for i in range(spaces)...
  18. I

    Looking for programming exercises for OOP in Python

    Hello I learned object oriented programming in Python from a book. But it does not have any programming exercises. I do not learn very much unless I do some programming exercises. It helps to hone the skills. So, I am looking for some exercises if OOP Python is taught in universities. Usually...
  19. Eclair_de_XII

    I'm not able to write a script that reduces a matrix to RREF in Python

    Summary:: I'm not asking for help, but I'm asking for an opinion. Is this a sign that I probably should not be pursuing a career in software development or computer science? I basically feel like this in general wrt any subject I am studying, really, whenever I feel stumped on a given problem...
  20. M

    How can we define the __mult__ method to return a Complex object?

    Hey! 😊 Construct a class named Vector that expresses the meaning of the vector of numbers. The initialization function, __init__ will take as a argument a tuple corresponding to the vector. This tuple will be stored in the variable named coord. Also, __init__ will calculate the Euclidean...
  21. M

    How do we properly set and get instance variables in a class?

    Hey! :giggle: Construct a class named Student which when initializing its objects has the following variables : - first_name (string) - last_name (string) - email (string) The class should also support the following functions implemented as functions (methods): - set_id_number: set a...
  22. shivajikobardan

    I need to make an application that uses database in python

    I need to make an application that uses database in python, what should I make? Firstly I need to tell about me. I know 0 about programming. I have learned basics of python only. What are the apps that use database that are upto my level of programming? I am planning to use django...
  23. shivajikobardan

    Python - Confused in list comprehension

    I want to find difference between two list. I came across sth called list comprehension. I can't tell you how confused I am with this. # Python 3 code to demonstrate # to remove elements present in other list # using list comprehension # initializing list1 list1 = [1, 3, 4, 6, 7] #...
  24. shivajikobardan

    Find next perfect square -- Not working in python

    def find_next_square(sq): # Return the next square if sq is a square, -1 otherwise sq2=(sq**1/2) xyz=isinstance(sq2, int) if (xyz==True): print("Is perfect square") nextsq=sq+1 print("Next perfect square=",nextsq**2) else: print("Not...
  25. shivajikobardan

    Find next perfect square not working in python

    def find_next_square(sq): # Return the next square if sq is a square, -1 otherwise sq2=(sq**1/2) xyz=isinstance(sq2, int) if (xyz==True): print("Is perfect square") nextsq=sq+1 print("Next perfect square=",nextsq**2) else: print("Not perfect...
  26. shivajikobardan

    Nested for loop in python, understanding with dry run?

    Here is the code that I am talking about-: n=int(input("Enter a number")) for num in range(2,n+1): for i in range(2,num): if(num%i==0): break else: print(num,end="") If I give n=5 output should be 2,3,5. Here is my dry run. Everything is fine except for 2...
  27. shivajikobardan

    How to check whether a string is odd palindrome in python?

    I am learning to code and 1 thing that surprises me is how do I internalize all the code? I understand the code. I know the algorithm as well. But I want to be able to solve any types of problems(related ones) after learning 1 code. How do I become able to do that? So for that I am first trying...
  28. shivajikobardan

    How to check a string is odd palindrome in python?

    I am learning to code and 1 thing that surprises me is how do I internalize all the code? I understand the code. I know the algorithm as well. But I want to be able to solve any types of problems(related ones) after learning 1 code. How do I become able to do that? So for that I am first trying...
  29. shivajikobardan

    How to learn python programming and get a web developer job?

    I am learning absolute basic python from udemy course. Till now I see no improvements at all. Except some small small improvements. How should I approach to learn python? I have 0 basics of programming even though I had already studied C and C++ as well as data structures and algorithm. I...
  30. fresh_42

    Explore Alan Turing's Computable Numbers & Generate Pi with Python

    I found this article about Alan Turing and his concept of Turing machines on the AMS website. Since we often get questions about countability and computability I thought it is worth sharing. https://blogs.ams.org/featurecolumn/2021/12/01/alan-turing-computable-numbers/ It also contains a Python...
  31. C

    Comp Sci Validating Braces Placement for Expression Evaluation

    Here's what I've done: Mentor note: replaced icode tags with code=python and \code pair. def valid_braces_placement(s, L): if len(L)==0: return False string = '' for element in L: string = string + str(element) D = ['+','-','*'] return...
  32. SamRoss

    How can I get the RUN button in Visual Studio Code to turn GREEN again?

    I have been using Visual Studio Code for a couple months now and it has been fine. When I want to run some code, there is usually a little green triangle button in the top right corner that I can click on. A few days ago, that triangle turned white only for Python files (it is still green for...
  33. shivajikobardan

    How do for loops work in python?

    str1="hello" for stringElement in str1: print("str1","=",stringElement) Strings are arrays in python and they are represented like this. Now I want to understand how the for loop is working here. My dry run-: for h in str1 print h for e in str1 print e and so on till...
  34. shivajikobardan

    Error occurred in pycharm python IDE

    # # A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffd51d4257f, pid=9852, tid=11684 # # JRE version: OpenJDK Runtime Environment JBR-11.0.12.7-1504.40-jcef (11.0.12+7) (build 11.0.12+7-b1504.40) # Java VM: OpenJDK 64-Bit...
  35. shivajikobardan

    Confused in name binding in python

    (I Didn't use code formatting here as I felt it was not necessary) I have read multiple textbooks, articles and watched multiple videos about name binding in python. Till now what I understand can be summarized in this-: x=1 means name x is binded to object "1" z=x and we know x=1 => z=1 so...
  36. shivajikobardan

    Confused about name binding in python

    (I Didn't use code formatting here as I felt it was not necessary) I have read multiple textbooks, articles and watched multiple videos about name binding in python. Till now what I understand can be summarized in this-: x=1 means name x is binded to object "1" z=x and we know x=1 => z=1 so...
  37. shivajikobardan

    Best book to keep as reference for python?

    1) Basic python only no data science or machine learning or game development. 2) I have CS experience and some programming experience but I am really bad programmer, so you can discount my programming experience. But I can learn cs concepts on the go. 3) Contains lots of solved and unsolved...
  38. shivajikobardan

    What is the best interpereter/IDE for python basic programming?

    What is the best IDE out there? It should be easy to use. Not as easy as online editors though.
  39. ORF

    Binned Maximum Likelihood fit in python?

    Hi, I have been using Python for a while now, but so far for Least-squares fits using curve_fit from Scipy. I would like to start using Likelihood method to fit binned and unbinned data. I found some documentation in Scipy of how to implement unbinned likelihood fit, but I have not managed to...
  40. user366312

    How can I calculate hydrogen bonds in a specific direction w.r.t. a C-

    I need to calculate H-bonds in a specific direction of a C-alpha atom of a protein. And, I need to calculate that from a PDB file. Can anyone give me a general guideline/direction/idea regarding how to do that? N.B. I need to write a python program.
  41. S

    Comp Sci A Question about modulus R in Rabin Karp Algorithm

    Hello, I am learning trying to set up a code that searches for a certain pattern in the text by implementing Rabin-Karp Algorithm. When setting up the Rabin Karp hash function, I have been told that I should set a value q in order to lower the time complexity of the function, and that q should...
  42. D

    Python How does one assess progress when learning a programming language?

    I'm a physics major (Junior) who would like to learn a programming language. Many suggest Python as a good starting language, so let's suppose that is the language I want to first learn. This isn't for employability or general usefulness; rather, I'm just curious. How exactly does one go about...
  43. F

    How to correctly use the "global" keyword in Python

    Hello, I am learning about functions and namespaces and I have a question about the keyword global. Variables defined inside a function are local variables and cannot be used outside of the function by the rest of the program (by using the return keyword, we can assign the value of a local...
  44. Arman777

    Understanding Object Type in Python

    As far as I know, there is no object type in python. How it's determined? For instance, we know that 2 is an object and it belongs to the int class. Similarly, 2.1 is an object, and it belongs to the float class. From my research, I have learned that data type ##\equiv## class. Then what the...
  45. Arman777

    Changing file icon via cmd or python script

    Is it possible to change the icon of a file via python or cmd in windows ? In my previous post I hava manage to change folder icon but I am not sure how to do that for files. Any ideas ?
  46. Arman777

    Changing folder icon in desktop.ini via python

    I have created this python program to create a desktop.ini file in a test folder and then change the icon of it. However, the program is something like this import os desktop_ini = ["[.ShellClassInfo]\n", "IconResource=C:\\Users\\Arman\\Desktop\\Coding\\Desktop...
  47. F

    'hold off' equivalent in python

    In MATLAB one can 'hold off' to remove a previously drawn thing on the same graph. How about in python?
  48. M

    Question about a Python for loop

    Hi All I'm learning python and have never seen a for loop positioned like this: integers = [4, 5, 7] strings = [str(integer) for integer in integers] I've only ever seen for loops positioned at the beginning of lines. Is this usual? How can I know when this is okay? I think I would have tried...
  49. Arman777

    How does Python tell that an integer is actually an integer?

    Look at this example, >>> a = 97 >>> type(a) <class 'int'> >>> bin(a) '0b1100001' >>> b = ord('a') >>> b 97 >>> type(b) <class 'int'> >>> bin(b) '0b1100001' Is this means that the string 'a' and the integer 97 stored as the same binary in the memory ? If so then how can python tell the...
  50. user366312

    How can I implement a multi-task deep learning neural network?

    I have 3 classes (A, B, and C). I have 6 features: train_x = [[ 6.442 6.338 7.027 8.789 10.009 12.566] [ 6.338 7.027 5.338 10.009 8.122 11.217] [ 7.027 5.338 5.335 8.122 5.537 6.408] [ 5.338 5.335 5.659 5.537 5.241 7.043]] These features...
Back
Top