Python Definition and 661 Threads

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

    Python How can I properly handle exceptions in my Python program?

    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...
  2. Z

    Python How to Correctly Reverse Digits in Python Using Recursion?

    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...
  3. T

    Python Python Help: Convert Celsius to Fahrenheit

    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...
  4. T

    Python Python Help: Convert Celsius to Fahrenheit

    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...
  5. S

    Python Noob question re Python on Windows PC

    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...
  6. E

    Python Ideas for simple programs to write in Python please

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

    Python Need help with sorting a Python dictionary.

    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...
  8. D

    Python Quick Python color coding in editing question

    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
  9. S

    Python How Can I Correct My Python Regular Expressions Code for Analyzing Swallow Data?

    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...
  10. B

    Python Python code for mapping numbers n text file

    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...
  11. H

    Python Learn Python for Physics: Introduction vs Scientific Programming

    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...
  12. Z

    Python Opening Files in Python - Newbie Question

    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'...
  13. Z

    Python Don't understand this python function

    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
  14. Z

    Python Beginner Python - simple function

    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...
  15. Z

    Python Beginner Python - better way to write this?

    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...
  16. N

    C/C++ Python or C++ for ChemE Major: Which is Most Useful?

    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...
  17. J

    Why Doesn't My Blasius Equation Script Match Fluid Mechanics Data?

    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...
  18. Z

    Python Storing Functions in a List - Python Q&A

    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...
  19. Z

    Python Python: Retrieve Function Name Without Execution

    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
  20. Z

    Python How to Replace Digits in a String with Characters from Another String in Python?

    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...
  21. Z

    How can I efficiently capitalize items in a list without modifying the original?

    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...
  22. T

    Python How can I fix the error in my custom Python exception class?

    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...
  23. Z

    Python Quick Python question - how to change input to *

    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...
  24. K

    Python Why is Python Telling Me My Variable is Not Defined?

    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...
  25. B

    Python Bad form not to use functions in Python?

    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.
  26. D

    Python Loging into a webpage using python.

    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'...
  27. D

    Python How can I log into a webpage using python and access data?

    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 =...
  28. clope023

    Python Python Else/Elif Syntax Error: Troubleshooting Tips and Common Mistakes

    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...
  29. Avatrin

    Python How can I use Euler's Method in Python to solve a differential equation?

    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...
  30. P

    Python Learning Python -Beginner Question

    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...
  31. C

    Python Dirac Algorithm in Python (or similar)

    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.
  32. B

    Python Intro to python: using - in / and %

    im reading a book intro to python, I am confused by what is ment by the following >>>-17/10 -2 i do not understand this explain pls NOT A HW
  33. C

    Python Maintaining Syntax Highlighting in Python IDLE

    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...
  34. W

    Python Finding primitive roots using python

    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...
  35. L

    Python Fortran Routine calling a Python Function

    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...
  36. D

    Python Why won't this python code work?

    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...
  37. J

    Python How to write a data file in Python

    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...
  38. D

    Python Find Numerical Physics Problems in Python

    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...
  39. K

    Python Python Beginner Help: Removing Duplicate Words from Lists

    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...
  40. T

    Python Replacing multiple spaces in Python

    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...
  41. H

    Python Python FFT help, non linear scaling

    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...
  42. D

    Python Can Python scipy.optimize.fmin() Optimize More Than One Variable at Once?

    Hi All, I am trying to optimize for more than 1 variable at the same time. is that possible?
  43. A

    Python How to make scientific notation the default in the Python interpreter?

    Hi, I'm tired of reading numbers like 695500000, and using %e all the time is not a practical solution. Thanks.
  44. G

    Python Stupid Question about Python Learning Curve

    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...
  45. M

    Python What is the Python syntax for checking if a number is a palindrome?

    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...
  46. D

    Python Calculate Area Under Gaussian Curve w/ Python Reimann Sum

    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...
  47. Z

    Python Python Tutorial for Beginners With Little Programming Knowledge

    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...
  48. M

    Python Learning Python and Sage - Advice Appreciated

    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!
  49. V

    Python Python: Calculating the average of scores and separatign into letter grades

    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...
  50. D

    Python Python: Help with bestfit line and outliers

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