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

    Need help with random walk simulation on a Manhattan grid in Python?

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

    Python Help for CSC131: Random Walk Simulation

    "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...
  3. clope023

    Python Vector Class no attribute error

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

    Why does Python 3's print(1!=0==0) return 'True'?

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

    C or Python for Mechanical Engineering Projects

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

    [Python] finding the correct data mining approach

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

    How to Define and Work with Digits in Python?

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

    Should I Improve My Skills in C or Python During My Vacation?

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

    C Programming: Deepen Understanding & Learn Python in 1 Month

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

    More efficient way to do this using Python?

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

    Efficient Factorial Calculation in Python: Recursive vs. Iterative Methods

    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)...
  12. K

    Is Python the Future of Programming?

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

    What to do after basic programming (Think Python)

    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?
  14. S

    Learning Python: Where to start?

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

    What is causing an error when opening a PPM image file in Python?

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

    Executing abaqus job using python script

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

    Summation for a Python function

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

    C++, java, or python programming

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

    Python Plotting Help: Solving Circular Orbit with Matplotlib and Numpy

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

    Parsing arguments to a python file

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

    Python highest prime factor problem.

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

    Need Help Turning One File into Thousands of Files (in Python)

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

    Python: Generating All Possible Combinations?

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

    Why Does My Python Function Give a NameError in the Shell?

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

    Create Chess Game & Chatbot w/ Python in 7 Months

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

    Python program to verify primes

    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)...
  27. X

    Lagrangian interpolation of sin(x) in Python

    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...
  28. V

    Fixing ValueError: Setting Array Element w/ Sequence in Python

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

    How do I turn the number 120 to 00120 in python?

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

    Why Does My Python Matrix Multiplication Code Raise a TypeError?

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

    How to Create a Significant Figures Calculator in Python?

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

    Troubleshooting a Roulette Game Program in Python

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

    Save Output of Python Program to TXT File: Tips & Tricks

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

    Help getting the correct output with for a simple python model

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

    Problem reading file manipualting values therein, Python

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

    Why does this code work, python

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

    Trouble with Python sum function

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

    Python code for generating prime# list and evaluting a number

    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 ()...
  39. D

    Help Getting the Tonry model of Peculiar velocity field running in python

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

    Solving a Set of Equations with Python Odeint | Code and Example

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

    Python multiplication table and user input

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

    Two Body problem using Verlet Algorithm Python

    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)...
  43. M

    Python loops with running total

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

    Learning Python Loops: From Counting to Exponents of 2

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

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

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

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

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

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

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