Python Definition and 662 Threads

  1. M

    Python One-line Python Code that returns a sequence of integers

    Hey! 😊 I want to write a one-line Python generator or iterator expression that returns the sequence of integers generated by repeatedly adding the ascii values of each letter in the word “Close” to itself. The first 10 integers in this sequence are: 67, 175, 286, 401, 502, 569, 677, 788, 903...
  2. Graham87

    Comp Sci Orbit of the Earth - numerical methods leapfrog

    I am attempting this homework exercise part b). I've modified my code but I get error overflow message. My goal is to modify my code so it returns kinetic and potential energy of Earth's orbit. I made a new f(z,t) and modified the rows 99 and 100 with dz[2]=-G*M*m/r, and dz[3]=0.5*m*y**2 but...
  3. Graham87

    Comp Sci Orbit of Earth: Plotting Trajectory

    I am attempting this homework exercise but my plot does not show the whole trajectory. I don't know if it is something wrong with my equations or if it is a plotting matter. Cheers!This is my code:import matplotlib.pyplot as plt import numpy as np import scipy.integrate as spi G =...
  4. S

    Python Python, unittest.mock : Getting object & method names from method_calls

    Let's say that my_mock.method_calls gives me this array: [call.thing.pop(3, 4), call.thing.bob.smash(6, 7), call.thing.jig.slurp(4)] How can I extract the names 'thing', 'pop', 'bob', 'smash' etc. from this array?
  5. M

    HTML/CSS Python - HTML : Isn't this a dictionary ?

    Hey! 😊 I have written a program in Python where API calls to the server to get currency exchanges. Now I want to add a part for the user, i.e. with html. The endpoint is : @route_rates.route("/all/") def get_all(): return render_template("currency.html", my_currency =...
  6. R

    Python In Python flask I am trying to set up the SMTP for emails in outlook

    I am trying setting up flask email for outlook. I had it working with gmail I found this link https://superuser.com/questions/1521236/how-to-allow-less-secure-app-access-in-microsoft-email I tried MAIL_SERVER= 'smtp.office365.com' MAIL_PORT = 587 MAIL_USE_TLS = True...
  7. M

    Python Python - Endpoint : Can the function not return an array of dictionaries ?

    Hey! 😊 I am trying to write a code for a server in Python and I got stuck. I gave as an input a csv file and using pandas we get a dictionary where the titles are the keys and the inputs are the values. From that we get the below : I have written the below endpoint to get all the...
  8. M

    Python 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...
  9. ergospherical

    Python 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.
  10. M

    Python 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...
  11. user366312

    C/C++ 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...
  12. F

    Python 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...
  13. 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...
  14. R

    Python 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...
  15. M

    Python 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...
  16. R

    Python 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...
  17. 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...
  18. M

    Python Why Does My Python Code Output None Instead of the Next Permutation?

    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...
  19. 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)...
  20. 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...
  21. shivajikobardan

    Python How to implement this pseudocode in python?

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

    Python 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...
  23. M

    Python 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!
  24. M

    Python 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)...
  25. I

    Python 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...
  26. Eclair_de_XII

    Python 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...
  27. 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...
  28. 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...
  29. shivajikobardan

    Python 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...
  30. shivajikobardan

    Python 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] #...
  31. shivajikobardan

    Python 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...
  32. shivajikobardan

    Python 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...
  33. shivajikobardan

    Python 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...
  34. shivajikobardan

    Python 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...
  35. shivajikobardan

    Python 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...
  36. shivajikobardan

    Python 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...
  37. F

    Python 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...
  38. 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...
  39. 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...
  40. shivajikobardan

    Python 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...
  41. shivajikobardan

    Python 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...
  42. shivajikobardan

    Python 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...
  43. shivajikobardan

    Python 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...
  44. shivajikobardan

    Python 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...
  45. shivajikobardan

    Python 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.
  46. ORF

    Python 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...
  47. 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.
  48. 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...
  49. 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...
  50. F

    Python 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...
Back
Top