Hello, dear PFers. I'm currently beginning to learn Python and I got stuck at one exercise.
Homework Statement
Basically, I'm supposed to create a simple program that will calculate the position of an object according to the formula y(t) = v0*t - 0.5*g*t**2. Parameters v0 and t are supposed...
Homework Statement
def rev(n):
'''Return the result of reversing the digits in integer n. For example,
rev(512) should return 215.'''
pass
Homework Equations
The Attempt at a Solution
def rev(n):
'''Return the result of reversing the digits in integer n. For example...
Im having trouble with a basic python assignment in one of my classes. Its supposed to ask the user for temperatures in Celsius and convert them to Fahrenheit, which it does fine. The problem is that its also supposed stop asking the user if he gives it 0, which means the end of the list of...
Im having trouble with a basic python assignment in one of my classes. Its supposed to ask the user for temperatures in Celsius and convert them to Fahrenheit, which it does fine. The problem is that its also supposed stop asking the user if he gives it 0, which means the end of the list of...
Hi
I want to start learning Python and am a little nervous about installing it (from www.python.org) and running it on my main Windows Vista PC. I have scary memories from previous programming experience over 20 years ago of it being possible to corrupt important files or bits of memory by...
I currently have little experience in programming and would like to improve my skills. The most complex program I've made so far has been a definite integral calculator that uses either right handed or left handed riemann sums to approximate the definite integral (although it fails to be...
Homework Statement
Hi there,
I need to sort a Python dictionary based on its values which are ints, then return the ordered list as the keys.
I am thinking to make the inverse of the dictionary, take values and sort, then map back with the inverse dictionary.
The problem is that...
When I've been programming in Python for a while I noticed that the color coding in IDLE goes away. If I restart IDLE, the colors come back. Why is it doing this? How can I maintain the color in there without having to restart a bunch of times?
Thanks
Homework Statement
This isn't really a homewrok/coursework question, but I didn't know where to put it. I'm trying to teach myself python over the summer and I seem to have got stuck on regular expressions. I want to read a .txt file with data for various kinds of swallows, laden/unlden...
Dear Programmers
I am having text file having huge data.
From the text file i would like to map the two numbers that are present in the same brackets and the values should not considered if they are present in different numbers.
say for example I want to map number "4758 & 3895" that are in...
Is it better to start learning Python using a introduction to python book (Think Python) or a scientific programming book (e.g. A Primer on Scientific Programming with Python, 2009)? I have little to no programming experience.
I'd use python solely for physics computation/simulations. I was...
Homework Statement
Hi, this might be silly but I'm not sure what the syntax is for the read function...
I'm trying to open a file on my desktop, it is a text file called testfile.txt, how do I make python know where to find it?
I go:
f = open('C:\Users\Truman\Desktop\testfile.txt'...
Homework Statement
Hi,
I'm not sure what this does:
s = 'hello'
I understand
s[::-1] would reverse the order of the letters and
s[1::] slices the first letter
but how come
s[1::-1] returns 'eh' ?
Homework Equations
The Attempt at a Solution
Homework Statement
Write the definition of a function typing_speed , that receives two parameters. The first is the number of words that a person has typed (an int greater than or equal to zero) in a particular time interval. The second is the length of the time interval in seconds (an...
Hi,
This compiles, I just wanted suggestions for fewer lines. Thanks.
Homework Statement
Need to write a function for this:
Given an int variable, return a factor of that int. If the input is not between 0 and 100 return -1. If there are more than one distinct factors, return...
I'm a chemE major, entering my sophomore year. I have used python in physics classes, but that was minimal experience.
I want to begin learning a language this summer; I have no other prior experience. My main interest is cryptography, but I don't think this will amount to anything other...
Hi everybody
I'm writing a script in Python to solve the Blasius equation but it does not work (well, script works and it generates the plot), numerical results does not match with data I've seen in fluid mechanics books.
Please anyone could help me? Thank you very much
Script is...
Homework Statement
Hello,
I just have a small question with Python.
Is it possible to store multiple functions in a list? So I can call them from the list?
Like if I had :
def func1():
...
def func2():
...
def func3():
...
Can I put them in a list and call them from...
Homework Statement
Hi there,
I just have a quick one here..
Is there a way to bring the NAME of a function? Not execute it?
Like if I had
def apple():
return
Can I get it to print "apple" somehow?
Thanks
Homework Equations
The Attempt at a Solution
Homework Statement
Write the follow function:
def substitute_digits (s, subst):
s is a string and subst is a string of length 10. Return a copy of s, where each digit in s is replaced by the second character of subst, '1' is replaced by the second character of subst, ... , and '9' is...
Homework Statement
I'm supposed to write a function that does this:
def capitalize_items_2(lst):
Return a new list with the same items as lst, only in upper case. lst is a list of strings. This function does not change lst
Homework Equations
The Attempt at a Solution
def...
Homework Statement
For an introductory Python course, one of the problems I am required to do involves creating a MyError class that inherits from Exception. Its purpose is to handle possible wrong inputs to the int() function and to return an error statement that includes what was input.
I...
Homework Statement
Hello,
Just a quick question here for Python.
I'm using raw_input to get the user to type in a string, but I want the letters to display as * (like when you enter a password) as they type it. (But not actually register as *). Is this doable in Python?
Thanks...
Homework Statement
Hi. So I'm stuck on a few things right now, but the main one is that Python is telling me that one of my variables is not defined. I have stressed over this for about an hour now trying everything to change it, and I cannot seem to find issue.
Homework Equations...
I have a 100 line code which is liable to increase, so far I have not included any user defined functions, so it is one stream of code. In c I was taught to put everything I could into functions, is this the case in python i.e. would I be frowned upon for not using functions?
Many thanks.
Hi,
I am trying to access some data online, but I am having trouble getting past the actual authentication process.
import cookielib
import urllib, urllib2
if __name__ == '__main__':
urlLogin = 'https://www.hobolink.com'
uid = 'userid'
password = 'xxxxxxx'...
Hello ladies and gentlemen,
I have grabbed a code for emailing using python. This isn't my end goal, but I think its a logical place to start and get used to the smtp library. here is the code
import smtplib
def prompt(prompt):
return raw_input(prompt).strip()
fromaddr =...
Hello, the title says it all; I am trying to teach myself Python using version 2.7.1 aka matplotlib or PYLAB via the MIT opencourseware as well as the tutorial from the site I downloaded it from; I am having a very frustrating time using it as system continues to return any variant of else...
Hi
Here's is the differential equation I need to solve using Euler's Method:
v' = 5 - 0.5v^2
I need to plot the position x(t), velocity v(t) and acceleration a(t) as a function of time.
v(0) is 0
I have the data for time:
s = linspace(0, 12, 121) #(delta t is 0.1)
But, that's about it...
Learning Python --Beginner Question
Hey All,
I am translating a whole lot of code from MATLAB to Python/NumPy/SciPy. However, I am having a lot of trouble creating column vectors. I know that in MATLAB it would go like this:
a = [1,2,3,4,5,6,78], colvec = a'
if anyone know the...
I was wondering if anybody knows of any code available to perform tensor analysis in Python or in other language; I was wondering if there is any computational method for finding constraints in a lagrangian via the Dirac Algorithm.
Homework Statement
I am a novice programmer and have just started programming on Python. When one types a command, the commands are highlighted in a certain color. When I open a new window and run the module, the commands lose their color. it is quite annoying. is their trick to keep the...
Im not sure if this should go in the math/number theory section or here, but here it goes:
how do programs calculate the primitive roots mod n of extremely large primes? My program will only go up to 12-14 bits before having memory errors caused by storage of the totient of the prime number...
I have been trying to merge some python with fortran, to build a nice interface but still be fast. I spent the last two days learning how to use f2py, buy everything would be so much easier if I could call a Python function from Fortran instead of doing the other way around.
Anyone know how...
lists = [(2 * i + 1) for i in range(100)]
i = 0
while (i < 100):
if(lists[i] == 3):
lists.remove(lists[i])
i = i + 1
print lists
It is giving me an error about the index being out of range. I am new to python and I am not understanding this error.
Edit: Fixed it. This is by...
Hi guys
I've done a Runge-Kutta script for the Lorenz Equations in python, I need to write data for (t,x,y,z) in a .dat file in order to reprint in a table. How can a do it?
Imported routines are:
import sys, pylab, numpy
from pylab import *
from mpl_toolkits.mplot3d import Axes3D...
I'm searching a book, or a place on the net where I'll find tons of examples of numerical problems in physics (mainly quantum mechanics) written in Python.
I have tons of books about Python, but none have good examples on problems like tunneling, solving Schrodinger eq for various potentials...
Homework Statement
I have a simple question with python.
I have a text file that's been converted into a bunch of lists like this.
[blah, blah]
[blah, blah, blah]
[a, a, d]
[g,x,d,s,a]
etc..
now i want to loop over all of these lists and append all the words into a new list...
Homework Statement
Write a function spacereplace(txt) that removes two or more spaces in a row, replacing them with a single space. Any other characters should remain the same.
The Attempt at a Solution
I tried this:
def spacereplace(txt):
f=txt.replace(" "," ")
return f...
Im writing a program in python to simulate the propagation of a gaussian beam through a thick lens and to the focussing point using Fourier optics.
Due to the strength of the focussing I need a lot of data points so that I have a decent resolution at the focus. To speed things up and to...
Stupid Question about Python Learning Curve :D
Sooooo...
I have to get some sort of menial minimum wage job in the near future, and I would be okay with this if it gave me the time to study books or think about philosophy (a night clerk/cashier or something, etc.)
Regardless of what...
I'm doing the http://projecteuler.net/" problems for garbages and giggles, and was working on problem 4 which requires finding the largest number palindrome (e.g. 10301, 54345) that is the product of two 3-digit numbers.
Below is my code, and I'm pretty sure Python will reproduce the error...
Hi I have a program that is to calculate the area under the curve of a Gaussian distribution.
The integral from -inf to inf is 1, and my Reimann sum program calculates close to 1.5pi = numpy.arccos(-1)
a = 1 / (StandDev * pow(2*pi,0.5))
b = MPCAverage #MPC is the x-axis of my gaussian curve...
I've been working with python for about 4 or five months. I understand how to use boolean, a little bit of I/O, making functions, writing my own classes, and importing modules. Pretty much the bare basics. Outside of this python experience, I have little knowledge of programming. So, can...
I have no backbround in programming or science/mathematics software, but time and desire to learn...
is learning
Phyton and Sage a good idea?
Advice appreciated!
Homework Statement
I'm suppose to write up a program where I need to take a file that contains a list of
numbers. Example:
30
40
40
80
and so on, these number represent letter grades. 90~100 = „A‟, 80~89 = „B‟, 70~79 = „C‟, 60~69 = „D‟, all other scores = „F‟. So what I'm suppose to do for...
I've been having some trouble with outliers messing up my best fit line on my scatter plot in python. I'm using numpy's polyfit function to calculate the slope and y intercept of the best fit line, however I always seem to get one or two points which throw off the slope enough to make quite a...