Python Definition and 655 Threads
-
Why doesn't the makeSix function change the value of the variable?
I'm reading the online tutorial "How to Think Like a Computer Scientist", which is a Python tutorial. There is an exercise, which I'm trying to figure out. What happens if you call a function and you don't do anything with the result (i.e., you don't assign it to a variable or use it as part of...- Mogarrr
- Thread
- Functions Python Tutorial
- Replies: 9
- Forum: Programming and Computer Science
-
Python Python 2 vs Python 3 in physics
Hey, This might sound like something that I should have posted to the "computing & technology" forums, but I disagree. I know that beginners should probably start with Python 3 instead of python 2, as "python 2 is legacy and python 3 is the future". I already bought a book on python 2...- DataGG
- Thread
- Physics Python
- Replies: 6
- Forum: Programming and Computer Science
-
M
Python Press-Schechter function in python
I want to write program in python that gives "redshift", range of "M" and range of "dn/dM" as input and plots "Press-Schechter" function and delivers a graph as output. would you please give some hints? I'm beginner in programming and I don't know how to start.- mahya
- Thread
- Function Python
- Replies: 1
- Forum: Programming and Computer Science
-
M
Python Plotting Press-Schechter using Python
How can I plot "Press-Schechter" function using Python for redshift 0, 0.5 and 1?- mahya
- Thread
- Plotting Python
- Replies: 3
- Forum: Programming and Computer Science
-
Python How can I add pictures to my python game using JGrasp and PyGame?
Hello. I am creating a text-based video game using python, and I was wondering how I could put pictures from my Mac into the game. I am using JGrasp if it helps to know.- ignacio_cabero
- Thread
- Pictures Python
- Replies: 1
- Forum: Programming and Computer Science
-
Python 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.- ignacio_cabero
- Thread
- Python
- Replies: 2
- Forum: Programming and Computer Science
-
T
Python 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...- TheQQ
- Thread
- Book Physics Python
- Replies: 6
- Forum: Programming and Computer Science
-
Python 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...- TheDemx27
- Thread
- Python Web
- Replies: 4
- Forum: Programming and Computer Science
-
Python 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- 462chevelle
- Thread
- Engineer Python Student
- Replies: 8
- Forum: Programming and Computer Science
-
S
Python 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...- Spencero94
- Thread
- Bit Homework Python
- Replies: 2
- Forum: Programming and Computer Science
-
T
Python 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] =...- thegreenlaser
- Thread
- Array Numpy Operations Python
- Replies: 14
- Forum: Programming and Computer Science
-
Python 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"...- NATURE.M
- Thread
- Python
- Replies: 2
- Forum: Programming and Computer Science
-
P
Python 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...- PaulaS
- Thread
- Nonlinear Python System
- Replies: 8
- Forum: Programming and Computer Science
-
G
Python 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...- gothloli
- Thread
- Pendulum Python Spring System
- Replies: 1
- Forum: Programming and Computer Science
-
T
Python Can someone suggest the best IDE for python
can someone suggest the best IDE for python which must be similar to code blocks- towuzzi
- Thread
- Python
- Replies: 2
- Forum: Programming and Computer Science
-
C
Python [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...- codymc94
- Thread
- Iss Python Rocket Trajectory
- Replies: 2
- Forum: Programming and Computer Science
-
P
Python 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...- PotentialE
- Thread
- Building Database Python
- Replies: 1
- Forum: Programming and Computer Science
-
M
Python 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' |...- mynick
- Thread
- Instruction Python
- Replies: 5
- Forum: Programming and Computer Science
-
Python 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+)\](.*)')...- Borek
- Thread
- Bug Python
- Replies: 2
- Forum: Programming and Computer Science
-
P
Python 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...- PotentialE
- Thread
- Ideas Programming Projects Python
- Replies: 4
- Forum: Programming and Computer Science
-
W
Python 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...- wyosteve
- Thread
- Code Combinations Python Vectors
- Replies: 1
- Forum: Programming and Computer Science
-
C
Python 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...- chipotleaway
- Thread
- Python
- Replies: 2
- Forum: Programming and Computer Science
-
S
Python 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...- Swimmingly!
- Thread
- Fun Program Python
- Replies: 3
- Forum: Programming and Computer Science
-
Python 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...- maverick280857
- Thread
- Python
- Replies: 5
- Forum: Programming and Computer Science
-
2
Python 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...- 2sin54
- Thread
- Program Python
- Replies: 4
- Forum: Programming and Computer Science
-
S
Python 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...- stargazer3
- Thread
- Class Function Python
- Replies: 4
- Forum: Programming and Computer Science
-
P
Python 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...- Punkyc7
- Thread
- Database Python
- Replies: 3
- Forum: Programming and Computer Science
-
Python 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...- TheBigBadBen
- Thread
- Python Resources Study Summer
- Replies: 4
- Forum: Programming and Computer Science
-
Python 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...- clope023
- Thread
- Monte carlo Plotting Python
- Replies: 1
- Forum: Programming and Computer Science
-
Python 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...- cepheid
- Thread
- Loops Python Stupid
- Replies: 7
- Forum: Programming and Computer Science
-
T
Python 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"...- TylerH
- Thread
- Overlapping Python
- Replies: 2
- Forum: Programming and Computer Science
-
M
Python 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)...- mrcleanhands
- Thread
- Python Recursion
- Replies: 4
- Forum: Programming and Computer Science
-
J
Python 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...- Juliayaho
- Thread
- Code Program Python
- Replies: 1
- Forum: Programming and Computer Science
-
P
Python 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...- PotentialE
- Thread
- Python
- Replies: 2
- Forum: Programming and Computer Science
-
T
Python 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...- thegreenlaser
- Thread
- Computational Python
- Replies: 18
- Forum: Programming and Computer Science
-
G
Python 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...- gravenewworld
- Thread
- Coding Gui Python
- Replies: 2
- Forum: Programming and Computer Science
-
A
Python 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...- Adyssa
- Thread
- Operations Python
- Replies: 2
- Forum: Programming and Computer Science
-
Python 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...- Hercuflea
- Thread
- Beginner Python
- Replies: 1
- Forum: Programming and Computer Science
-
Python 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...- Saladsamurai
- Thread
- Program Python Running
- Replies: 3
- Forum: Programming and Computer Science
-
T
Python 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...- TylerH
- Thread
- Class Error Python
- Replies: 4
- Forum: Programming and Computer Science
-
E
Python 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...- eximius
- Thread
- Force Formula Lennard-jones Program Python
- Replies: 1
- Forum: Programming and Computer Science
-
M
Python 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...- maximus123
- Thread
- Python Rutherford Rutherford scattering Scattering
- Replies: 5
- Forum: Programming and Computer Science
-
E
Python 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...- epr2008
- Thread
- N-body problem Python
- Replies: 10
- Forum: Programming and Computer Science
-
F
Python 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...- funcosed
- Thread
- 2d Axis Histogram Matplotlib Plot Polar Python
- Replies: 4
- Forum: Programming and Computer Science
-
A
Python [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...- Avarus
- Thread
- Gradient Optimization Python Variable Window
- Replies: 2
- Forum: Programming and Computer Science
-
V
Python 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...- Vespero
- Thread
- Calculation Graph Python Shortest distance
- Replies: 1
- Forum: Programming and Computer Science
-
S
Python 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...- stargazer3
- Thread
- Computing Python Scientific Scientific computing
- Replies: 8
- Forum: Programming and Computer Science
-
S
Python 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...- sola maths
- Thread
- Integration Numeric Python
- Replies: 4
- Forum: Programming and Computer Science
-
J
Python 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...- jbay
- Thread
- Body Python Rk4 Two body problem
- Replies: 11
- Forum: Programming and Computer Science
-
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 =...- JesseC
- Thread
- Equivalent Matlab Python
- Replies: 5
- Forum: MATLAB, Maple, Mathematica, LaTeX