4,305 Posted Topics

Member Avatar for MrNoobieCoder

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 …

Member Avatar for MrNoobieCoder
0
276
Member Avatar for goo_1

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))

Member Avatar for vegaseat
0
328
Member Avatar for krystosan
Member Avatar for krystosan
0
283
Member Avatar for RHNation

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

Member Avatar for Lardmeister
0
4K
Member Avatar for Paraborn

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)`

Member Avatar for woooee
0
243
Member Avatar for Ancient Dragon

Yes, you can learn to play the piano in less than one day. But, who wants to listen?

Member Avatar for vegaseat
2
416
Member Avatar for vegaseat

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.

Member Avatar for rubberman
1
6K
Member Avatar for vegaseat

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.

Member Avatar for jack.zgx
1
4K
Member Avatar for dp121307
Member Avatar for TrustyTony
0
697
Member Avatar for joester007

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

Member Avatar for AndrisP
0
4K
Member Avatar for vegaseat

Just a little fun with Python's named tuple, behaves like a class but is much leaner.

Member Avatar for vegaseat
2
681
Member Avatar for vegaseat
Member Avatar for vegaseat
2
1K
Member Avatar for ddanbe

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 …

Member Avatar for vegaseat
1
387
Member Avatar for vegaseat

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, …

Member Avatar for vegaseat
0
1K
Member Avatar for kamalashraf

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; }

Member Avatar for Ancient Dragon
0
324
Member Avatar for farmwife

Welcome back BearofNH! Interesting to know that a loaded down Firefox could give you problems. I use Chrome and have no problems.

Member Avatar for vegaseat
0
218
Member Avatar for marethamogale

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 …

Member Avatar for vegaseat
0
159
Member Avatar for Dani

Delphi is a rapid development system using Object Pascal for its language. A fancy IDE, like Visual C++ uses C++. Delphi came first.

Member Avatar for seblake
0
1K
Member Avatar for dabasank
Member Avatar for vegaseat
0
136
Member Avatar for marethamogale
Member Avatar for nitin1
Member Avatar for Gribouillis

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]

Member Avatar for Gribouillis
3
3K
Member Avatar for RHNation

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 …

Member Avatar for vegaseat
0
8K
Member Avatar for Ancient Dragon
Member Avatar for chris99

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.

Member Avatar for farmwife
0
6K
Member Avatar for Reverend Jim

A flashback in history ... First you read through people's mail, then you make them disappear in the middle of the night.

Member Avatar for Reverend Jim
0
828
Member Avatar for Ankurjain123

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 …

Member Avatar for vegaseat
0
362
Member Avatar for Ancient Dragon

I use my TV to fall asleep, not sure if 3D would have the same effect? Maybe the 3D programs are more interesting.

Member Avatar for Dani
0
238
Member Avatar for <M/>
Member Avatar for <M/>
0
192
Member Avatar for nitin1
Member Avatar for vegaseat
0
245
Member Avatar for steven woodman

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.

Member Avatar for stultuske
4
399
Member Avatar for onalenna.bobeilwe

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

Member Avatar for farmwife
0
235
Member Avatar for farmwife

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?

Member Avatar for farmwife
0
4K
Member Avatar for Rebecca_2

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 …

Member Avatar for vegaseat
0
228
Member Avatar for vegaseat

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.

Member Avatar for Lardmeister
2
531
Member Avatar for Ismatus3

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 …

Member Avatar for Ismatus3
0
5K
Member Avatar for vegaseat

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.

2
669
Member Avatar for vegaseat

The code shows you how to create a persistent to file dictionary of data using the python module shelve.

Member Avatar for Gribouillis
4
887
Member Avatar for Skyline77
Member Avatar for somjit{}
-7
588
Member Avatar for ohnbabygal

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 …

Member Avatar for cnplane
-1
162
Member Avatar for Taruna_1
Member Avatar for Jacklittle01
Member Avatar for Gribouillis
0
248
Member Avatar for Taruna_1

Without module re ... word = 'Cat' result = ''.join('a' for c in word) print(result) # aaa

Member Avatar for vegaseat
0
323
Member Avatar for np complete

Some help ... prime numbers are only divisible by unity and themselves integers less than 2 and even numbers other than 2 are not prime

Member Avatar for Gribouillis
0
237
Member Avatar for Hamza_4

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 …

Member Avatar for vegaseat
0
248
Member Avatar for martin.schmidt.9465

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')

Member Avatar for martin.schmidt.9465
0
20K
Member Avatar for Ene Uran
Member Avatar for spyindiarahul

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.

Member Avatar for <M/>
-2
1K
Member Avatar for Reverend Jim
Member Avatar for ddanbe

Could be your IDE acting up. Also your line 6 needs to be print() No need to putz around with sys

Member Avatar for vegaseat
0
277

The End.