Harvard has graduated some 52 billionaires, with a collective fortune of $205 billion. That ranks them number one!
deceptikon commented: Giving away answers is not being helpful -3
Harvard has graduated some 52 billionaires, with a collective fortune of $205 billion. That ranks them number one!
Ruby does not support keyword arguments in functions, something I have been using with Python a lot.
If you have a room with 16 people, how many times can they shake hands once with each other?
Stacks are used in assembly language a lot to store data. Python is a much higher language and stacks are rather transparent in use.
Python has a module called deque (double_ended_que) with methods appendleft() and popleft() which behave like the push and pop of a stack.
The built-in Python functions sorted() and sort() are highly optimized and a good choice to use.
I think you made a very good effort!
But you need to let folks know what you are after.
I took the liberty to update the code to work with Python27 and Python32 using the utility at
"C:/Python32/Tools/Scripts/2to3.py"
Here is the result:
# remove all jpeg image files of an expired modification date = mtime
# you could also use creation date (ctime) or last access date (atime)
# os.stat(filename) returns (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)
# tested with Python24 vegaseat 6/7/2005
# updated for Python3x with 2to3.py utility program
import os, glob, time
root = 'D:\\Vacation\\Poland2003\\' # one specific folder
#root = 'D:\\Vacation\\*' # or all the subfolders too
# expiration date in the format YYYY-MM-DD
xDate = '2003-12-31'
print('-'*50)
for folder in glob.glob(root):
print(folder)
# here .jpg image files, but could be .txt files or whatever
for image in glob.glob(folder + '/*.jpg'):
# retrieves the stats for the current jpeg image file
# the tuple element at index 8 is the last-modified-date
stats = os.stat(image)
# put the two dates into matching format
lastmodDate = time.localtime(stats[8])
expDate = time.strptime(xDate, '%Y-%m-%d')
print(image, time.strftime("%m/%d/%y", lastmodDate))
# check if image-last-modified-date is outdated
if expDate > lastmodDate:
try:
print('Removing', image, time.strftime("(older than %m/%d/%y)", expDate))
#os.remove(image) # commented out for testing
except OSError:
print('Could not remove', image)
There is also a code snippet here at DaniWeb:
http://www.daniweb.com/software-development/python/code/216538/removing-outdated-files-python
There is a limit to recursions in Python,
find the limit with
sys.getrecursionlimit() --> usually 1000
Can be changed with
sys.setrecursionlimit(new_limit)
Oh yes, yogurt ice cream with blueberries and dark chocolate syrup.
"Life's greatest happiness is to be convinced we are loved."
-- Victor Hugo
How about an iPad, or something with diamonds on it?
However,
print float('0x123abc')
does not work
So maybe this would be better:
def is_float(s):
try:
float(s)
return True
except:
return False
for s in ['1e3', '+3.14', '-77', '0x123abc']:
if is_float(s):
print float(s)
else:
print s + ' value gives float() error'
You could display it in a swing.JLabel
The unemployment rate for recent college graduates in Architecture is 13.9 percent in the US. The highest of all degrees.
Actually, once you get past the beer sold by the big makers, the best beers in the US are made by the many local Microbreweries.
A species of South African dung beetle has been shown to use the Milky Way to navigate.
The letter N is pronounced 'ene' in Spanish. Usually used in referring to a person from the North.
"Hard work spotlights the character of people: some turn up their sleeves, some turn up their noses, and some don't turn up at all."
--- Sam Ewing
"When I need a little advice about Saddam Hussein, I turn to country music."
—- George Bush Sr. (1991)
Try this:
def lap_average(lap1, lap2):
# get minutes, seconds, centiseconds
m1, s1, c1 = [int(x) for x in lap1.split(':')]
m2, s2, c2 = [int(x) for x in lap2.split(':')]
# form a list of centisecond values
tlist1 = [m1*60*100, s1*100, c1]
tlist2 = [m2*60*100, s2*100, c2]
# get the total centiseconds
centis = sum(tlist1) + sum(tlist2)
# take integer average
centis = centis // 2
# get minutes, seconds from centiseconds
seconds, centis = divmod(centis, 100)
minutes, secs = divmod(seconds, 60)
print('-'*33)
print("Given lap times %s %s" % (lap1, lap2))
print("Average time = %02d:%02d:%02d" % (minutes, secs, centis))
# test times
lap_average('03:40:00', '05:20:00')
lap_average('03:00:02', '02:00:00')
lap_average('02:25:50', '06:50:75')
lap_average('00:02:00', '00:03:00')
lap_average('00:02:20', '00:04:40')
lap_average('02:40:40', '03:30:30')
lap_average('02:60:30', '60:40:40')
''' result ...
---------------------------------
Given lap times 03:40:00 05:20:00
Average time = 04:30:00
---------------------------------
Given lap times 03:00:02 02:00:00
Average time = 02:30:01
---------------------------------
Given lap times 02:25:50 06:50:75
Average time = 04:38:12
---------------------------------
Given lap times 00:02:00 00:03:00
Average time = 00:02:50
---------------------------------
Given lap times 00:02:20 00:04:40
Average time = 00:03:30
---------------------------------
Given lap times 02:40:40 03:30:30
Average time = 03:05:35
---------------------------------
Given lap times 02:60:30 60:40:40
Average time = 31:50:35
'''
The console screen can be cleared with multiple print():
for x in range(40):
print('')
Or simply:print('\n'*40)
If you have the Windows OS, maybe you should look into Portable Python and run your code from a USB flashcard, and also use the PyScripter IDE that comes with it.
For the free download and info see:
http://www.portablepython.com/releases/
Since you are a beginner I would download Python version 2.7.3 it makes working with older code examples much easier.
The average would be
(lap1 + lap2)/2
you would have to add the lap times as milliseconds then take the result and
recreate the minutes:seconds:milliseconds format
C is great for low level coding. You are talking about a high level task and could switch to a higher level language to make your life more productive.
''' ps_image_viewer101.py
view an image with Python using the PySide GUI toolkit
PySide is the official LGPL-licensed version of PyQT (QT)
Python and PySide are available for Windows, Linux and Apple OS X.
If you have Windows, download and execute the Windows self-extracting
installers in this order.
For Python33 (get the 32 bit version):
python-3.3.0.msi
free from:
http://python.org/download/
For PySide:
PySide-1.1.2.win32-py3.3.exe (based on QT483)
free from:
http://developer.qt.nokia.com/wiki/PySide_Binaries_Windows
'''
from PySide.QtCore import *
from PySide.QtGui import *
app = QApplication([])
# create the window/frame
win = QWidget()
# set location and size
win.setGeometry(100, 50, 500, 688)
# set the title
win.setWindowTitle("PySide Image Viewer")
# get an imagefile you have in the working folder
# or give full file path
fname = "cogtrain-500x688.jpg"
# load the picture in a form PySide can process
image = QPixmap(fname)
# use a label to display the image in
label = QLabel(win)
label.setPixmap(image)
win.show()
app.exec_()
Sorry, I thought the question was
how to print '% ' in printf()
Used the code to test my reinstalled CodeBlock IDE. Works now.
Sorry, couldn't get my CodeBlock IDE to work, so I did it on the ideone.com C compiler.
Try something like that:
// power series dev using a loop
// value of e = 2.71828182846
#include <stdio.h>
int main()
{
int n, f;
float x;
float e;
x = 1.0;
f = 1;
e = 0.0;
//e = 1+x/1!+x2/2!+x3/3!+x4/4! ...
//e = 1 + x * x*2.0/2 + x*3.0/(2*3) + x*4.0/(2*3*4) ...
for ( n = 1; n < 11; n++ ) {
f *= n; // factorial, don't exceed 12!
e += x*n/f;
printf( "%f %d %d\n", e, n, f);
}
getchar(); // wait
return 0;
}
// show "How are you %dad%"
#include <stdio.h>
int main()
{
printf( "How are you %cdad%c", '%', '%');
getchar(); // wait
return 0;
}
Two eggs sunny side up, toast and peppermint tea.
The Alien from the Alien movie.
Pops up when least expected, eats folks with those nasty titanium teeth, and sloppers slime all over.
The rich are getting poorer, they had to take 15 Senators off the payroll.
... Jay Leno
The Fiscal Cliff is solved.
Or:
There is a Santa Claus after all.
According to the 2012 Gallup pole the five most popular women are:
Hillary Clinton
Michelle Obama
Oprah Winfrey
Condoleezza Rice
Sarah Palin
I guess girls in swimsuits don't make it.
This may give you a few hints:
''' csv_rread102.py
find duplicate email addresses in a csv file
'''
# csv type test data
# name, surname, job_title, company, email
csv_data = '''\
Arden,Adam,clerk,ACME Tools,aaden@gmail.com
Bison,Bert,manager,Ideal Plumbing,bertbison@idel.com
Clark,Clara,assistant,ACME Tools,clarkc@gmail.com
Arden,Adam,supervisor,ACME Tools,aaden@gmail.com
Clark,Clara,receptionist,ACME Homes,clarkc@gmail.com
'''
import csv
fname = "aaa_test7.csv"
# write the test data file
with open(fname, "w") as fout:
fout.write(csv_data)
# read the test data file back in
with open(fname, "r") as fin:
reader = csv.reader(fin)
# create a dictionary of email:frequency pairs
email_freq = {}
for row in reader:
print(row) # test
name, surname, job_title, company, email = row
email_freq[email] = email_freq.get(email, 0) + 1
print('-'*70)
# refresh reader object
with open(fname, "r") as fin:
reader = csv.reader(fin)
# make a list of all rows that have duplicate emails
duplicate_emails = []
for row in reader:
name, surname, job_title, company, email = row
# add row to list if email frequency is above 1
if email_freq[email] > 1:
duplicate_emails.append(row)
# show results
import pprint
pprint.pprint(email_freq)
print('-'*70)
pprint.pprint(sorted(duplicate_emails))
''' my result >>>
['Arden', 'Adam', 'clerk', 'ACME Tools', 'aaden@gmail.com']
['Bison', 'Bert', 'manager', 'Ideal Plumbing', 'bertbison@idel.com']
['Clark', 'Clara', 'assistant', 'ACME Tools', 'clarkc@gmail.com']
['Arden', 'Adam', 'supervisor', 'ACME Tools', 'aaden@gmail.com']
['Clark', 'Clara', 'receptionist', 'ACME Homes', 'clarkc@gmail.com']
----------------------------------------------------------------------
{'aaden@gmail.com': 2, 'bertbison@idel.com': 1, 'clarkc@gmail.com': 2}
----------------------------------------------------------------------
[['Arden', 'Adam', 'clerk', 'ACME Tools', 'aaden@gmail.com'],
['Arden', 'Adam', 'supervisor', 'ACME Tools', 'aaden@gmail.com'],
['Clark', 'Clara', 'assistant', 'ACME Tools', 'clarkc@gmail.com'],
['Clark', 'Clara', 'receptionist', 'ACME Homes', 'clarkc@gmail.com']]
'''
Solve not just the problems tomorrow, but also the problems of today tomorrow.
"All of us learn to write in the second grade. Most of us go on to greater things."
___ Bobby Knight
"Winners never quit and quitters never win."
___ Vince Lombardi
"We have to be realistic. If we don't win, life will continue."
___ Hayden Fry
"Success without honor is an unseasoned dish; it will satisfy your hunger, but it won't taste good."
___ Joe Paterno
"I never learn anything talking. I only learn things when I ask questions."
___ Lou Holtz
"Do not let what you cannot do interfere with what you can do."
___ John Wooden
A closer look at recursive functions:
''' func_recursion_GDC1.py
exploring recursive functions, in a nutshell:
return exit value if condition is met else
call function again with adjusted paramters
'''
def GCD(x, y):
'''
a recursive function to return the
Greatest Common Divisor/Denominator of x and y
'''
return x if y == 0 else GCD(y, x%y)
# testing ...
print(GCD(240, 150)) # 30
print(GCD(14, 63)) # 7
print(GCD(14, 0)) # 14
print(GCD(14, 3)) # 1
I find video tutorials simply too distracting, usually put on by some ugly dude with poor pronunciation.
Evolutionists:
An almost chicken laid the egg the first real chicken came out off.
Creationists:
God made the chicken and then it laid an egg.
Putting up with relatives and missing my friends.
SWYFDST = Seniors watching young folks doing stupid things
According to the CDC on the average US day, 85 people are shot dead.