4,305 Posted Topics
Re: Look at this example, it should give you hints ... ''' input_integer1.py loop until you get an integer input ''' # make input() work with Python2 and Python3 try: input = raw_input except: pass def get_int(): """this function will loop until an integer is entered""" while True: try: # return … | |
Re: You could also follow this approach ... infilename = input("Enter the name of the file: ") with open (infilename ,'r') as infile: data = infile.read() count_newlines = data.count('\n') count_chars = len(data) count_words = len(data.split()) print("Lines = {}".format(count_newlines)) print("Characters/bytes = {}".format(count_chars)) print("Words = {}".format(count_words)) | |
Re: Also note that json (JavaScript Object Notation) expects your strings to be in double quotes. | |
Re: You got to learn how to pass arguments to and from functions. Also this does not make sense: #constants for the shipping prices weight_one <= 2 weight_two > 2 weight_three > 6 weight_four > 10 | |
Re: A nice effort! You can simplify your first function ... def getEveryOther(creditCardNum): mylist = [] for x in creditCardNum: mylist.append(int(x)) firstEveryOther = mylist[-2::-2] secondEveryOther = mylist[-1::-2] return firstEveryOther, secondEveryOther ... and call it with ... `firstEveryOther, secondEveryOther = getEveryOther(creditCardNum)` | |
Re: Yes, you can learn to play the piano in less than one day. But, who wants to listen? | |
In Las Vegas random numbers move billions of Dollars in and out of gamblers' pockets. For the mildly inquisitive here is a test of three simple generators. | |
An example how to plot the function y = sin(x) using the WinApi function SetPixel(). The plot is centered along a line at pixel y = 200. Add an x-axis and a couple of tickmarks and it could look impressive. | |
Re: On first blush it could be an indentation error in your class. | |
Re: I have a working algorithm, but it is in Python. You should be able to apply it to C++ code. Note: In Python // is an integer division. See: http://www.daniweb.com/software-development/python/threads/20774/starting-python/19#post2017691 | |
Just a little fun with Python's named tuple, behaves like a class but is much leaner. | |
Applying the famous Gauss algorithm to determine the date of Easter for a given year. | |
Re: Very good! Follow the Python style guide and your code will look rather polished. I had to smile when I saw the long-worded camel style of C# show up in your Python code. My problem is that I am not that good of a typist. The radius was a little … | |
Factorials get large very rapidly. The factorial of 13 is !13 = 1*2*3*4*5*6*7*8*9*10*11*12*13 = 6227020800. This number already exceeds the unsigned long integer, and gets into the real money as the politicians say! This program uses an array of characters to store the factorial as a numeric string. Go ahead, … | |
Re: You can also multiply sum by 1.0 to turn it into a float ... float average (int sum, int size) { float a=1.0*sum/size; return a; } | |
Re: Welcome back BearofNH! Interesting to know that a loaded down Firefox could give you problems. I use Chrome and have no problems. | |
Re: raw_input() returns a string value, so you have to convert it into an integer. Your code should look something like this ... score = int(raw_input("Enter your score (0 to >9999): ")) if score>=0 and score<=999: print "nothing to brag about" elif score>=1000 and score<=9999: print "good score" elif score>=9999: print … | |
Re: Delphi is a rapid development system using Object Pascal for its language. A fancy IDE, like Visual C++ uses C++. Delphi came first. | |
Re: I assume you need the full pathname of each file. Python module glob will help you. | |
Re: Give us the code you have written so far and the problems you had. | |
Re: Samsung might be a good spot. | |
Re: Access a dictionary directly ... [code=python]# a food:price dictionary food_dict = { 'soymilk' : 3.69, 'butter' : 1.95, 'bread' : 2.19, 'cheese' : 4.39 } # pull one key item like 'bread' out of the dictionary print("Bread = ${bread:4.2f}".format(**food_dict)) # Bread = $2.19 [/code] | |
Re: I would enter tip and tax in percent ... def main(): # this program calculates the total price of a meal after inputting # cost of food, percent tip and sales tax print ('Welcome to the Meal Calculator Program:') print() # get the cost of food using the input function … | |
Re: The lesson is: "Carry your gun with you all the time!" | |
Re: I think both Ene's and ghostdog74's solutions to the sort list by wordlength project are very clever! One could also use list comprehension for this. | |
Re: A flashback in history ... First you read through people's mail, then you make them disappear in the middle of the night. | |
Re: Run an external program from within Python code with subprocess.call(["program-name", "arg1", "arg2"]) rather than os.system("program-name arg1 arg2") since os.system() does not allow the Python program to run in the background, whereas subprocess does. Example ... # play a midi file with a small external midiplayer: # from http://www.kanatachoralsociety.ca/memberscorner/AKoffPlr.exe # mplayer2.exe … | |
Re: I use my TV to fall asleep, not sure if 3D would have the same effect? Maybe the 3D programs are more interesting. | |
Re: The improved camera and the fingerprint sensor sound interesting. | |
Re: Most countries that buy oil have to keep Dollars around to pay for it. | |
Re: Coffee is a person who has been coughed upon. The winner of the rat race is still a rat. Veni, Vidi, Velcro. I came, I saw, I stuck around. Nebraska: At least the cows are sane. Taxation WITH representation isn't so hot, either! Stable relationships are for horses. | |
Re: You can keep your actual password secret by using md5 one_way hashing. Or just something simple like shown here: http://www.daniweb.com/software-development/python/threads/459789/coding-for-privacy#post1998322 | |
Re: GTK has always been tempramental to install on Windows machines. I like to use Tkinter for quick stuff and PySide (PyQT) for more fancy coding problems. I wonder if GTK has made it easier to create and use a listbox? | |
![]() | Re: Another approach ... # find selected files in the working folder using module glob # glob takes care of upper/lower case # for instance it finds .txt .Txt .TXT etc. # glob works with Windows and Unix import os import glob # pick a directory/folder folder = "C:/temp" os.chdir(folder) print("list … |
Using the PySide GUI toolkit will make selecting, copying and pasting encrypted and decrypted text somewhat easier. Not ideal yet, but it will be a good start for those of you who are not very familiar with GUI programming. | |
Re: Generally, create all image objects in __main__ to be persistent. If you create the image object in a function it will tie it to a function scope variable, Then when the function is done the image will be garbage collected. One potential way around this, try it in your code … | |
This short snippet shows you how to preprocess a text to remove punctuation marks, then do a word frequency count using Counter() from the Python module collections. Finally, two sorts are applied to display words with matching frequency in alphabetical order. | |
The code shows you how to create a persistent to file dictionary of data using the python module shelve. | |
Re: Engineers from India make up 60% of the special visa recipients in the USA. | |
Re: Jpowers22 is right, you need to use clock() to get to something that is about a millisecond. You also have to do the calculation about a million times to get a meaningful time to measure. Yes Ruby, computers are fast nowadays! [php]// time the sqrt() function Dev-C++ #include <iostream> #include … | |
Re: Give us an example of a dataframe. | |
Re: If you follow Lardmeister's advice, make sure your variable names are rather unique. | |
Re: Without module re ... word = 'Cat' result = ''.join('a' for c in word) print(result) # aaa | |
Re: Some help ... prime numbers are only divisible by unity and themselves integers less than 2 and even numbers other than 2 are not prime | |
Re: Just a hint ... bottle = "vial jug canteen urn" transport = "car automobile airplane scooter" mydict = {} for word in bottle.split(): mydict[word] = 'bottle' for word in transport.split(): mydict[word] = 'transport' #print(mydict) # test text_old = "he carried a jug of water and a canteen of brandy in … | |
Re: Try this ... from random import randrange x = randrange (0,100) y = randrange (0,100) #print (x)('x')(y) print("{}x{}".format(x, y)) answer = int(input('Type your answer here: ')) if answer == x*y: print ('Correct!') else: print ('Incorrect') | |
Re: Women want to be wooed, so buy her some nice jewelry, go out to places you both like, have some fancy dinners, and when she is in her best mood you ask the question. | |
Re: Could be your IDE acting up. Also your line 6 needs to be print() No need to putz around with sys |
The End.