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. ignacio_cabero

    Python Usage Among Scientists: A Brief Inquiry

    Hello, I'm new here to the PF, and I was wondering if anyone here uses Python? Thank you all.
  2. T

    What is the best book for learning python for physics applications?

    Hello, I would like to self learn python for my physics degree, but I don't really have an idea where to start. Could anyone recommend a good book out there for beginners (zero experience with programming)? I don't want anything too comprehensive; that's for comp sci majors. I'm really...
  3. TheDemx27

    Web Scraping with Python 3.4: Getting Started

    I'm starting this web scraper, and all I'm trying to do so far is to just retrieve the source code from the sites. Code: import urllib.request from urllib.request import urlopen urls = ["http://google.com", "http://nytimes.com", "http://www.rockpapershotgun.com/"] i = 0 while i...
  4. 462chevelle

    Python useful for engineer student?

    I'm taking linear algebra through edx just to get my eyes on the subject. Some of the work in the class requires you to to vector operations on Python. Is it going to be useful for me to learn this stuff for engineering? Or should i just focus on the linear algebra. Thanks
  5. S

    Having some trouble with a little bit of Python Homework:

    Homework Statement The problem shows as follows: An arithmetic progression is a sequence of numbers in which the distance (or difference) between any two successive numbers if the same. This in the sequence 1, 3, 5, 7, ... , the distance is 2 while in the sequence 6, 12, 18, 24, ... , the...
  6. T

    Python (Numpy) Non-Elementwise Array Operations

    Python (numpy) question: I have two 2D numpy arrays, A[i,j] and B[k,l], but the indexes are unrelated to each other (A and B won't even have the same dimensions in general). I want to be able to add/multiply these two together to get a 4D matrix: C[i,j,k,l] = A[i,j] + B[k,l] or C[i,j,k,l] =...
  7. NATURE.M

    Quick Question about Python concatenation

    Homework Statement Lets say we have two strings 'movies' and ' goto'. Now the question indicates to return this combination concatenated n times, except if n is negative, it is the same as if it were 0. The Attempt at a Solution Concatenation n times would yield: n*"movies goto"...
  8. P

    How to solve a system of nonlinear equations in python

    I have the following system of 3 nonlinear equations that I need to solve in python: 7 = -10zt + 4yzt - 5yt + 4tz^2 3 = 2yzt + 5yt 1 = - 10t + 2yt + 4zt Therefore I need to solve for y,z, and t. Attempt to solve the problem: def equations(p): y,z,t = p f1 = -10*z*t + 4*y*z*t - 5*y*t...
  9. G

    Solve non-dimensionalized spring pendulum system on python

    Homework Statement I'm supposed to solve the spring pendulum numerically on python 2.7, using odeint. The system is supposed to solved for the y -direction and the x-direction in terms of time. In class we did this for pendulum DE, but that only had x as the dependent variable, this system has...
  10. T

    Can someone suggest the best IDE for python

    can someone suggest the best IDE for python which must be similar to code blocks
  11. C

    [Python] Simulating rocket trajectory to ISS

    background information is that I have been working on code for a rocket launch to the ISS and I have gotten it close. The problem is when calculating the Force of drag, the problem occurs with it. As entering space, and for this "model" were going to say that temperature is 0 K in space or...
  12. P

    How can I build a database in Python?

    Does anyone have a good tutorial or start-up advice for building a database in Python? The only database software I've ever used is Microsoft Access, but I've heard it's possible to build databases in Python. I was thinking I'd start off with a simple database: a few tables that can draw...
  13. M

    Python problem with instruction open()

    I am fiddling with python v2.7.5,i am using Pyscripter version 2.5.3.0 x86 to write my program and i do not know how to deal with this problem when i run my program: PROBLEM: ___________________________________________ IOError:[Errno 2] No such file or directory:'words.txt' |...
  14. Borek

    Python bug, or am I misunderstanding something?

    I don't know python, yet I am trying to code something, just for fun. But I have hit some strange obstacle and I don't know if it is a bug in my Python version (dated, it is over a year old, under Raspbian), or is it me misunderstanding something? pattern = re.compile('\[(\d+)\]\[(\d+)\](.*)')...
  15. P

    Any ideas for intermediate-level programming projects in Python?

    I have recently learned Python programming as a self study and am proficient in using the syntax. I can currently make calculators and other operational tools in Python, but I can't use Python to actually manipulate a computer; there is ample instruction in basic programming on-line but not much...
  16. W

    Problem with python code. Combinations of 2-state vectors

    I am trying to find all combinations of a four element vector that contains only 1's and -1's. Ex (1,1,1,1),(-1,1,1,1),...(-1,-1,-1,-1) etc My idea to do this is pretty inefficient I am sure but I can't think of another way to do it, so here is what I was trying to do. I found how many total...
  17. C

    Graph X-Axis from CSV File with Python

    How do if you have a .csv file with 3 columns (independent, dependent, uncertainty in dependent variable), how do you make a graph so that the independent variable is the x-axis and the dependent is the y axis? All I've done is pylab.plot(data,"ko") pylab.show() The graph I get seems to...
  18. S

    Python: Fun problem. Solving Program is Bugged. Why?

    I hope I'm in the right section. This part is not important but this is thought behind the program. If you have n-mathematicians and each has a secret number. How many phone calls have to be made for all mathematicians to know all numbers? In this brute force approach I, hypothesize that you...
  19. maverick280857

    How Can I Vectorize a Computation in a Python Device Simulation Algorithm?

    Hi, I am working on a device simulation algorithm, and am implementing it in Python on my laptop that runs Arch Linux. A particular step requires me to perform a computation of the form \tilde{G} = G \Sigma_{c}^{in} G^{\dagger} where G and \Sigma_{c}^{in} are both N \times N matrices, and...
  20. 2

    Help with a simple Python program

    Homework Statement Hello. I want to write a program which finds the largest number in the sequence typed in by the user. However, when I type in a number it not only gets printed as the input value but gets re-printed as if I have done the print function of that number (though the final answer...
  21. S

    Python: modifying class from an inside function

    I feel very stupid right now. Should be an easy question, but I googled it to no avail. Basically, I have an class.object in my code which should be managed by a class.function For example, I want the following code: class Z: a=0 def mod(self): self.a=self.a+1...
  22. P

    How can I get specific elements from a tuple/list in Python without iterating?

    I am using python to get tuples from a db. I am doing cur.execute("Select Statement"); I use cur.fetchall to get the tuples. My question is how do you iterate over the returned tuples and store the columns into an array? I want to iterate over n tuples, not all the returned results...
  23. TheBigBadBen

    Learning Python: Seeking Resources for a Summer Study

    I'd like to try to pick up Python over the summer, while I have the free time. I do have some programming experience, and I've heard it's not too difficult to pick up. I've found some things here and there, but if anybody has any strong recommendations of a particular resource (pdf document...
  24. clope023

    Monte Carlo Python Plotting Question

    If this is better served in a section like Nuclear Engineering please let me know. Homework Statement Simulate the projection of a radiation source onto the plane of a collimated detector. Check if said projection is circular. The attempt at a solution What I want to do is...
  25. cepheid

    Troubleshooting Nested Loops in Python: Unexpected Output Explained

    My code isn't working, and the reason seems to be because nested for loops in python don't work according to my expectations. If I have some code like this: f1 = open('name_of_file1.txt', 'r') f2 = open('name_of_file2.txt', 'r') for line1 in f1: #stuff at this level should happen...
  26. T

    How can I modify my regex to allow for overlapping matches in Python?

    I'm writing a function to take a string like "aXYb" and return a regex in which the lower case letters act like actual character and the upper case become free variables. The regex generated from "aXYb" should match anything of the form a([a-z]+)([a-z]+)b. It does. But not exactly as "freely"...
  27. M

    Trouble understanding recursion (Python)

    I'm trying to understand a function which draws a koch curve using a library which draws (lt = left turn, fd = move forward, t represents an object class). def koch(t, n): if n<3: fd(t, n) return m = n/3.0 koch(t, m) lt(t, 60) koch(t, m) rt(t, 120)...
  28. J

    Python program help with my math code

    Hi I built this code that runs well. Is about calculating a student loan... The problem is that I wish I could create a table that will tell me in each column "payment number", "remaining balance", "interest amount", "principal amount" Can you help me do this? I am new to python and this is not...
  29. P

    Help with a basic, four-line python operation

    I am creating a program in Python 3.3 that converts miles to feet, my code is as follows: def Miles2Feet(): Miles = input('Enter distance in miles: '); Feet = 5280 * Miles; print (Miles, 'Miles =', Feet, 'Feet'); When I run this using 1 as an input number of miles, it does not...
  30. T

    Python 2 vs Python 3 for Computational Tasks

    I've decided to learn Python (having a background in C++ and Matlab), and I'm a little unsure about which version to get. I've read in a few places that Python 2.x is better because packages like numpy and scipy don't work with Python 3.x, but this seems to be out of date since as far as I can...
  31. G

    Modifying Future Value Program with a Python GUI

    Homework Statement To modify a future value program so that a user inputs the data w/ a GUI Homework Equations principal = principal * (1+apr) The Attempt at a Solution Anyone familiar w/ python coding? I'm a beginner. I'm absolutely stuck on this problem, I seem to have...
  32. A

    What is a more efficient way to perform bitwise operations in Python?

    I'm playing around in Python at the moment, and I came across an exercise to perform bitwise operations manually (without the built in & | ^ ~ operators). I understand the operations on paper, and I have a function here that performs them (& in this case, the others are similar): def...
  33. Hercuflea

    Learning Sage & Python for Beginner Programmers

    Hey everyone I am looking to learn the Sage software as an alternative to MATLAB. I would like to leaern Python as well. I have a bit of a limited programming experience (A in a Programming Principles course last semester which used Java). So I know loops, stacks, methods, class variables...
  34. Saladsamurai

    Python: Running a program - Should be simple

    Hello :smile: As strange thing is happening. I have created a simple file using emacs (on a Mac) that contains the following: def main(): print "hello!" if __name__ == "__main__": main() And I have saved it in the working directory as hello.py In a terminal...
  35. T

    Python: Old-style to New-style Class Conversion Causes Error

    I'm trying to convert my __init__ to __new__, but I can't find any docs on how the syntax differs or anything really, that pertains to how this bug could be caused by it. What am I doing wrong here? import copy; class grid(list): def __new__(self, size): self.size = size...
  36. E

    Lennard-Jones Force Formula Python Program

    I'm not looking for the answer, I just want some help with understanding the question. The main thing I'm stuck on is the characteristic binding energy and the characteristic molecular size. I've tried searching for these but I'm finding a lot of different stuff. Homework Statement All to...
  37. M

    Python and Rutherford Scattering

    Hello everyone I have been supplied with this eqn n=\frac{Nat}{16r^2}(\frac{2Ze^2}{4\pi\epsilon_0E_K})^2cosec^4(\frac{\phi}{2}) for Rutherford scattering. N is the number of alpha particles incident on a unit area of foil t is the thickness of the foil a is the number of atoms...
  38. E

    How to Solve N-body Problem with Python using Euler's Method?

    I was wondering if anyone could by any chance give me some help. I used Euler's method and the program runs, however, it doesn't give the correct solution. I honestly have no idea what's happening in the program, the problem has to be in the way I implemented Euler's Method. But I can't seem to...
  39. F

    Python, matplotlib plot 2D histogram on polar axis.

    Any python/matplotlib experts out there?? This one has been driving me crazy all day. I have three vectors, azimuth, frequency and power, which I would like to histogram and plot on a polar axis. I can plot a scatter plot this way no problem but the histogram gets messed up somehow. An example...
  40. A

    [Python] Optimization: determining gradient with variable window size

    Hi all, I'm not quite sure if this is the right place to post my question, so forgive me if its not... I've written a program in Python that analyses data that I got from a compression experiment (mechanical testing of rocks and such), and I've written a piece of code that estimates the...
  41. V

    BFS Shortest Distance of Graph Calculation in Python

    Homework Statement I have this problem essentially figured out. There's just one tiny problem that I can't seem to solve. I'm supposed to write a function bfs(G, v) which takes a graph G stored as a dictionary, and a starting vertex v. The function bfs performs a breadth-first-search...
  42. S

    Python, scientific computing, and supercomputers

    Hi there! I'm currently having great fun using numpy/scipy in python for astronomical data analysis. (I've been using C for this before, but it takes too much time to implement simple things that are in numpy/scipy already) Recently I've been told that most of people are using C or Fortran...
  43. S

    Can Python handle numeric integration with exponential functions?

    I'm trying to write a python program that is able to numerically execute functions of the form: y(t) = exp(Integrate[A(x),x]) within the bounds of 0 and t I tried using quad from scipy.integrate but it seems not to be able to evaluate expressions of this form. Any other suggestions on...
  44. J

    Two Body problem in python using RK4

    So I am writing a program in python to do RK4 for the two body problem. I want it to display a sphere moving around another. It currently displays one sphere for a split second and then it goes blank. Any suggestions? from __future__ import division from visual import * from visual.graph import...
  45. J

    MATLAB Python equivalent of MATLAB textscan?

    Is there one? Or do I really have to write something like this: from numpy import * with open('file.txt','r') as f: #read only data, ignore headers lines = f.readlines()[31:] # convert strings to floats and put into arrays for i in xrange(len(lines)): s =...
  46. L

    What Could be Causing Discrepancies in My Python Gas Simulation?

    Hello. I wrote a simple gas simulation in python, with pygame. In the simulation the atoms collide elastic collisions with each other and with the walls. Although the simulation does run and the collisions look realistic, when I try to calculate physical parameters like p,T,V,n and compare them...
  47. A

    PhD to Finance with just Python?

    I'm finishing my astrophysics PhD and looking for other career options. I do observational astrophysics, almost entirely based on Python coding on very large data sets. Lots of Numpy+SciPy, monte-carlo, modelling data doing non-linear fitting using maximum likelihood on computer clusters, stuff...
  48. E

    Finding largest number with no Diophantine representation (in Python)

    Homework Statement Write an iterative program to find the largest integer n such that the equation 6a + 9b + 20c = n where a, b, c are nonnegative integers, has no solution.Homework Equations We are given that the set of n in {x, x+1, x+2, ..., x+5} has nonnegative solutions a, b, c to the...
  49. S

    How can I efficiently shuffle and deal cards for a simple memory game in Python?

    So I'm working on a simple memory game nonGUI: Write a program that plays the memory matching game. When it start, the program prompts the user for the number of rows and columns for the game board that contains the cards. The total number of cards must be even. Assume that the board dimensions...
  50. M

    Trying to teach myself Python

    x=0 y = raw_input("""Up to what number would you like to locate primes?: """) for i in range(int(y)): x = x + 1 if x%2 and x%3 and x%5 and x%7: print x, '--> PRIME' elif x==2 or x==3 or x==5 or x==7: print x, '--> PRIME' elif x==1: print x else: print xI've been on break...
Back
Top