15,181 Topics
| |
This snippets shows how to have fun replacing multiple words in a text. The target words and the replacement words form key:value pairs in a dictionary. The search and replacement is done using Python's regular expression module re. The code also gives an example of a function within a function. | |
I could use some assistance My final project in a python class is to calculate the distance between 2 lat/long points. My code is really just managing the input & output portions, while using existing code (properly credited) in a function to do the actual calculations. I've got it working … | |
Hi. I am trying to make a script that will print out numbers in rapid succession after working a little with them. The script needs to write them in the console one after another (next line). The code works just fine when I do not utilize multi threading, but when … | |
im a beginner with python, and I'm having trouble with some functions. I'm pretty sure it might be a syntax error or how i set up the code, since i am a beginner, however, i have no clue why this code works. Here is the code, its for a tic … | |
Hello, When I'm using the 'open' function how should I specifiy the directory ? I'm getting an IOError and bit of confused! I'm not sure if my script is wrong or I've problems with specifying the directory. input = open('New.txt', 'r') text = input.read() wordlist = text.split() wordfreq = [wordlist.count(p) … | |
Hello, I'm trying to script a Caesar cipher with the key, I find this exercise too much for me at this moment! I just can't come up with an algorith to get this done. Please advise. key = {'a':'n', 'b':'o', 'c':'p', 'd':'q', 'e':'r', 'f':'s', 'g':'t', 'h':'u', 'i':'v', 'j':'w', 'k':'x', 'l':'y', … | |
python function that creates automatically a dropdown year selector (that is a "select" element poulated with all years starting from current and dating back to a given year)? I don't need day/month (otherwise i'd have used the datepicker), i just need the year! Thanks in advance | |
An example how to use Tkinter's OptionMenu() as a combobox to allow one year to be selected from an option list of let's say the past 15 years. | |
don't work this: bg_fon2 = PhotoImage(file='2.GIF') from tkinter import* import random root = Tk() root.geometry("896x626") canv = Canvas(root, height = 626, width = 896) bg_fon = PhotoImage(file='fon.GIF') canv.create_image(0,0,image=bg_fon,anchor='nw') class Fish: image = 0 coor = 0 direct = 0 real_img = 0 obj = 0 canv = 0 def fiish1(): … | |
hii I have a list having m1 m2 m3........ m922 and in each there are a1 a2 a3 a4 are there like m1=a1 a2 a3 a4 a5 a6 m2=a1 a2 a3 a4 a5 a6 m3=a1 a3 a5 a7 a8 a2 etc and i want this as m1=a1 a2 a3 a4 … | |
Is this considered good form when writing cross-platform code? #! /usr/bin/env python3 And how about this? if __name__ == "__main__": main() I've reviewed some recent sample snippets and not all of them use the shebang and the conditional main call, so I wasn't sure whether that is still considered good … | |
Hi guys Just started to get into Python so this site seems liek a gtreat resource for hints and tips. Nice to meet you all. Ben | |
I'm learning python (and programming in general) through Runestone Interactive. What do people think of that site as a place for beginners to learn python? Also, is there any harm in trying to learn perl and web design languages at the same time? I'm concerned about becoming confused. | |
Hello again :) I'm trying to define a simple "spelling correction" function that takes a string and sees to it that 1) two or more occurrences of the space character is compressed into one, and 2) inserts an extra space after a period if the period is directly followed by … | |
I am trying to get the following ENUM to work, but it's not working. Any help is appreciated. class Colour(Enum): WHITE = (255,255,255) BLACK = (0,0,0) RED = (215,45,45) BLUE = (45,87,214) YELLOW = (230,223,48) GREEN = (45,194,64) Using it: `Colour.BLACK` Error: /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 "/Users/blooop/main.py" Traceback (most recent call last): File … | |
num = int(input("Enter a number: ")) if num==0 or num<0: continue else: if num > 1: if (num % i) == 0: print(num,"is not a prime number") print(i,"times",num//i,"is",num) break else: print(num,"is a prime number") | |
I've to write a function that takes a list of English words and returns a list of Swedish words. For example, {"merry":"god", "christmas":"jul", "and":"och", "happy":gott", "new":"nytt", "year":"Ã¥r"} used to translate English into Swedish. def translate(a): a = {"merry":"god", "christmas":"jul", "and":"och", "happy":"gott", "new":"nytt", "year":"Ã¥r"} for k, v in a.iteritems(): print k,v … | |
I'm a beginner to Python and I decided to make a permutation finder program. Have fun and don't question the name. :) | |
Hello, I'm trying to define a function that takes an integer 'n' and a character and returns a string, 'n' characters long. I'm totally lost and I've nothing. I read in a forum "".join might help. But that too is beyond perceivable for me at this moment. I do have … | |
Hello, I've been trying to write a function that takes a value (i.e. a number, string, etc) x and a list of values a, and returns True if x is a member of a, False otherwise. This is the script I could think of. I'm not even sure what might … | |
I"ve been working on this dice game for the past few days. I made sure the game itself worked properly then I added a draw dice function that would show you the dice that were rolled on the canvas. I needed a continue button to make the rest of the … | |
I'm actually helping my wife. She's learning Python. Me? VB.net and C# are my preferance. So I try to help her. All she wants to do is paint a command button, use this to launch another program written in python. I have spent the past few days trying to find … | |
I'm trying to learn scripting in Python. So, I started using an exercise and it had this question for me. Define a function that computes the length of a given list or string. And I can't use the built in function len(). I tried the code below and I can't … | |
Hi I installed a different version of Python but how to choose edit with IDLE to open scripts in python 2.7 or python 3.2 on my Windows desktop? | |
For those of you who are inquisitive, here is a little Python program to approximate the value of pi to 77 digits. You can easily go further, just change the value n in range(n+1). | |
Recently I've been fooling around with some fun mathmatic (dont knwo if that is even a word) stuff. I recently took on the task of trying to calcualte PI. I have a very simple program in python that does this for me: import math from datetime import datetime top = … | |
I have a computer science project and it has all to do with list and such could someone please help me with it! | |
I've been messign around with Python a little recently. Though I now want to import one of my .py files into my "main" file, but I get an `"module" object is not callable` error. How do I actually do this then. My files: KeyGenerator.py main.py Code I use to import: … | |
Im personally learning how to program in python though I do know of other languages. Is Python the best to learn off? | |
Hello Guys, i am new to python, for a assingment i need to create a game (binary puzzle). im having problems to start with creating the bord, i saw some examples of creating a bord game on this forum but it didnt worked out for me. i want to create … |
The End.