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 =...
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...
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...
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...
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...
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...
This is an old lab assignment I never got around to finishing and we are allowed to resubmit it for partial credit. I don't really even know how to set up this program. I understand what I need, I just don't know how to implement it. Any help is appreciated.
"You may know that the streets and...
"A classic problem that can be solved using a list is a random walk. Imagine a drunken man standing on the center square of a sidewalk consisting of 11 squares. At each step, the drunk can elect to go either left or right. How long will it be until he reaches the end of the sidewalk, and how...
Hello all, my issue is in calling the attributes of a 3d vector class in python, this is the class I was working with:
import math
class Vec3:
''' A three dimensional vector '''
def __init__(self, v_x=0, v_y=0, v_z=0):
self.set( v_x, v_y, v_z )
def set(self, v_x=0...
print(1!=0==0) seems to print the value 'True'. I'm trying to understand why.
Does it first evaluate (1!=0) ?
Or does it first evaluate (0==0) ?
Or does it separate them into (1!=0)^(0==0) ?
I appreciate all help.
BiP
Hi,
I am majoring in mechanical engineering, and I have to take my first programming class, I have 2 options, a course that teaches C and another Python. Which one should I chose for ME? why? Which one do you think is more helpful for a ME major and is going to help me more in my future ME...
I'm having trouble finding the correct approach to my (fairly simple) example.
Let's say I have months of data for log-in times of a certain website. The data has been selected and cleaned such that I have a list of Date_Time for each log-in.
Now, suppose I wanted to predict the log-ins...
Homework Statement
This is not about one problem, it is rather about a type of problem:
How do I define, in Python, a number which is defined by its individual digits? For instance:
Pandigital numbers..
Palindromes..
Circular primes..
What commands do I need to work with to find these...
Im a Comp Eng student, and i have about 2 month of vacation, but i really got nothing to do.. I know C better than python, just wonder if in this 2 months, what you guys recommend i should get better at C or at python?
Note: those are the only two languages i know so I am open to other...
Im a Computer Science Major, i just finish a programming Class.. it was a C class, i got an A on the class it was a bit to easy in my opinion, but I am not confident in C
Im good with functions, variables, pointers, basic structs, etc
Im lacking understanding on structs using pointers...
Homework Statement
Its not really a homework problem as its just for a problem from an online Python tutorial but I thought it would fit in better here.
The problem is to find and then print out the all the web address links (clickable), from the source code of a web page.
The problem...
I tried the following code:
def factorial(n):
if (n == 0):
return 1
else:
return n*factorial(n-1)
def ncr(n,r):
return ((factorial(n))/(factorial(r)*factorial(n-r)))
number = 0
for n in range(100):
for r in range(100):
print ncr(n,r)...
Is Python the future??
I know currently in the sciences and physics especially, C++ is the language of choice. It is like this in my department, and looks to be that way everywhere else. However, in the computer science department, they don't even offer programming classes taught in C anymore...
I had finished Think Python, an introductory book on programming using python.
I'm a physics major. So I'd probably need simulations and computational skills. I tried searching Google for intermediate python books, found nothing.
Any suggestions on how to proceed?
I'll be working for most of the summer and won't be able to take classes in anything so instead I will be teaching myself a new programming language! I have experience with java already and I've heard from places around the web that Python is both fun and useful. I figure I'll give it a shot...
Homework Statement
I'm writing a program that will do simple image editing with ppm files. I can only use the graphics library and things in there. No PIL or Image module.
My problem is that I get an error that says "couldn't recognize data in image file "sole.ppm"
I know for a fact it is...
I'm not 100% sure where this belongs, but, I have a script that will allow me to modify the mesh size of an individual part in abaqus, and then execute a job on that part. my question is How do I go about changing the mesh size for multiple parts?
*edit* removed first part of question, wasn't...
Homework Statement
For formatting sake I've copied a picture of the problem and attached it here: http://i.imgur.com/kOjTy.png
Im not worried about the coding part right now I feel I can handle that, my main issue is trying to understand how the values in the summation are derived. It...
i know this topic has been discussed, but i would really want a direct reply and soon
Do i have to learn java or c++ in order for me to learn how to be a hacker?... good intentions off course, for security and privacy needs... please let me know. Thank you.
Homework Statement
We need to plot a two points (representation of planets). One is stationary and one is supposed to move on a circular orbit. We are using Python, Matplotlib and Numpy. We're not getting a circular orbit. We're just getting a line.
Homework Equations
a = F / mass1...
Dear forum,
I would like you to help me on .py scripts.
I am using CMS_SW and I want to do something like this:
cmsRun script.py file.root
where "file.root" is the file that the .py script needs to run... But I cannot find, how I declare it to the .py code...
these .py files, are configuration...
Homework Statement
The problem is taken straight from the Project Euler website:
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
The answer is 6857 as I must have solved it before but I can't figure out how I worked it out...
Homework Statement
I'm not sure if this is quite where this belongs since it's not homework really, but I just need help programming and I figured this would be the place to ask. It's related to undergraduate research I'm doing so if that's not kosher just say so!
I want to write a Python...
Need a little help here, if anyone can offer any advice. The problem I have is this. I have a dictionary that contains keys, and their possible values. I need to generate every possible combination of key values where each key can take on one of the possible values.
For example, the...
Newbie question...
I'm just learning python and need some help with creating functions. I want to create a function that is callable from python shell. I write a script as follows,
#!/usr/bin/python
def examplr(str):
print str
save it as example.py, then in shell try...
Hello!
I just started learning Python and I was wondering is it possible for a total beginnner to make a fairly decent chess game which could beat someone with a rating of 1700 or so ( that's my rating , lol :D ) .
Edit: I actually have a second idea of making some kind of chatbot, that would...
Homework Statement
I'm supposed to write a program which asks for an integer input, then determines if the input is a prime or not.
I wrote a program but I have 2 issues:
1) It works well for primes up to around the size of 30000~, then above that (I just tried 65537, for a weak upper bound)...
Homework Statement
The polynomial pL(x) is known as Lagranges interpolation formula, and the points (x0; y0),
. . . , (xn; yn) are called interpolation points. You will use Lagrange's interpolation formula to
interpolate sin x over the range [0; 2pi]. Begin with n + 1 interpolation points...
Homework Statement
fname[i]='%05s - %05s . %05s - %05s' % (xstart,xend,ystart,yend)
gives the error
ValueError: setting an array element with a sequence.
Basically I wanted to turn the statement '%05s - %05s . %05s - %05s' % ('50','50','50','50') to a string/name
that goes into an array of...
Homework Statement
I need to know how to change the format of a number in python
for example if I have a integer variable, xstart=0.
If i were to print(xstart) I want it to show 00000
and if I were to add 120 to xstart
xstart+=120
then print it
print(xstart) I want it to show 00120...
Hi all!
I'm learning programming on Python.
Currently, I'm trying to implement a recursive algorithm using a divide and conquer method to compute a product of matrices.
Yet an error occurs when I try to assign an element in a list (representing a matrix)
I can't understand where the problem...
Hi,
I am toying around with writing a significant figures calculator written in Python.
According to NIST and other sites, the preferred way for working with uncertainty is to report the uncertain digits in concise form: eg 11234(13)kg would be 11,234kg+/-13kg with 13 being 1 standard...
Hi guys
I'm trying to program a Roulette game on Python
My programs asks for inputs and I gave names to these inputs.
The point is, since I didn't assign these names before, the following error occurs:
UnboundLocalError: local variable 'color' referenced before assignment
I tried to get...
This isn't exactly part of my homework but I wanted to know how I could save the output of this program to txt file?
The program was my homework and it was to allow the user to enter the starting values for a multiplication tables columns and rows and print a 10x10table
I did it like so...
I have produced a model in python demonstrating the Tonry et al (1999) model of infall towards the Great Attractor and Virgo Attractor however I can't seem to achieve the correct pylab graph output I am looking for. Firstly I would like to be able to plot the 100 output values all on the same...
I was trying to write code that would read integers stored in a file, line by line and then save them to a list and average that list and display it, it didn't work. What can I do to correct this code, I believe that the error is in how I am treating the list but I am confused at why the...
This isn't quite homework, it was just in my textbook as an illustration. Below is a function to return a list in reverse order.
Why does it work? My brother tried to explain it to me but failed to clarify. The only line I don't understand is the third and what process takes place because of...
I don't know why we have to write a sum function for python when there already is one but
this is supposed to sum a list with varible values and I don't understand why it doesn't work, can someone help explain there error, I believe that I am not giving proper values to the line that adds but...
Homework Statement
I am attempting to allow a user to enter a number and check to see if it is in a list of already generated prime numbers Here's my attempt
Where can I put the code to allow the number to be checked, the prime list generator works fine alonedef buildPrimeList ()...
I am attempting to translate the model of peculiar velocity flow given by Tonry et al (1999) from fortran into python, the language we use on my course, however I am experiencing difficulties in getting the thing to run.
I have attached the original fortran (sbf2flow) and my attempt at...
I want to solve a set of equations using Python odeint, but output shows me it is wrong.
Can you help me? Thanks.
Code:
# -*- coding: utf-8 -*-
from scipy.integrate import odeint
import numpy as np
from pylab import *
import math
def func(y, t, k, c, Zr):
#px, py...
Homework Statement
I'm having and issue with this problem, and I don't understand what I'm doing wrong, I really want to understand the material
Write code that will print a multiplication table for 10 positive integers across the columns and 10 positive integers down the rows. Prompt the...
Homework Statement
Hi !
I'm trying to solve numerically two body problem using Verlet algorithm in Python. I wrote a code which looks like that :
import numpy as np
import scipy as sp
rm=np.array([0.,0.])
r0=np.array([2.,0.])
p0=np.array([0.,0.1])
dt=0.001
m=0.1
G=0.01
M=500.0def r(dt)...
I have a homework problem that I can't figure out, can someone help
--Create a function called sums that will prompt the user to enter integer values (either positive or negative). The function should keep separate running totals of the positive values and the negative values. The user should...
Hi everyone, I'm new to programming, studying python in school.
here's my first go at a loop to count up to 100 by 2, works fine
stop_count=100
count=2
while(count<=stop_count):
print count
count=count+2
But one of my practice problems is to use 'while' to
print 2 and all powers of 2...