I am using the Windows version and downloaded Python-2.3.4.exe and VPython-2003-10-05.exe then installed them in that order.
vegaseat
DaniWeb's Hypocrite
6,499 posts since Oct 2004
Reputation Points: 1,451
Solved Threads: 1,618
Skill Endorsements: 37
A note:
You don't need VPython to get started, it's just candy!
vegaseat
DaniWeb's Hypocrite
6,499 posts since Oct 2004
Reputation Points: 1,451
Solved Threads: 1,618
Skill Endorsements: 37
ono,
you better put that in as a regular thread in the Python Forum.
vegaseat
DaniWeb's Hypocrite
6,499 posts since Oct 2004
Reputation Points: 1,451
Solved Threads: 1,618
Skill Endorsements: 37
You made Python sound very interestung to me!
bumsfeld
Posting Virtuoso
1,512 posts since Jul 2005
Reputation Points: 409
Solved Threads: 238
Skill Endorsements: 1
I have played with Python a little and find it refreshing compared to C++. Gone is the long list of header files and references to obscure libraries in the make/batch file for the compiler. Also gone are the "gotchya" memory leaks.
I have to get used to the fact that type declarations are by inference, and there is only one type of string/character object. Another thing to get used to is the indention of statement blocks to replace {} and the semicolons are gone!
Ene Uran
Posting Virtuoso
1,830 posts since Aug 2005
Reputation Points: 676
Solved Threads: 255
Skill Endorsements: 7
Interesting this Python code. I highlighted the code and pasted it into IDLE editor and it runs fine. I am using Python 2.5.
Lardmeister
Posting Virtuoso
1,940 posts since Mar 2007
Reputation Points: 465
Solved Threads: 73
Skill Endorsements: 5
# hard to believe that Python23 was 8 years ago!
# ran the old Python23 code through the 2to3.py utility
# just to show the changes in Python syntax for Python3
print("Simple math like 12345679*63 = ", 12345679*63)
# print just an empty line (use '' to potentially work with Python27)
print('')
# display numbers 0 to 9
# the indentation before print makes it part of the loop
for number in range(10):
print(number)
# print also adds a newline, use a comma to prevent the newline
# in Python3 use end=' '
for number in range(10):
print(number, end=' ')
print('')
# import the math module for the sqrt() function
import math
# a little more complex this time
# \n is the newline character, % starts the format specifier
# Python does have its roots in the C language
# notice how we use the sqrt() function from the math module
# CYA: more specifically, sqrt() is a function in module math
print("\nSquare root of integers 0 to 9 formatted as a float with 4 decimals:")
for value in range(10):
squareRoot = math.sqrt(value)
print("sqrt(%d) = %.4f" % (value, squareRoot))
# now it gets a bit more hairy
print("\nDisplay integers 0 to 15 formatted to use 6 spaces ...")
print("(plain, zero-padded, hex and octal)")
print(" %s %s %s %s" % ('%6d', '%06d', '%6x', '%6o'))
for value in range(16):
print("%6d %06d %6x %6o" % (value, value, value, value))
print('')
print("\nA not so typical for loop:")
for food in "spam", "eggs", "cumquats":
print("I love", food)
print('')
# a short intro to string slicing
# a little cryptic at first blush, but very powerful
# [begin : < end : step] end is exclusive, step is optional
# defaults are index begin = 0, index end = length, step = 1
animal = "hippopotamus"
print("this is the string = ", animal)
print("length of string = ", len(animal))
print("exclude first 3 char = ", animal[3: ])
print("exclude last 4 char = ", animal[:-4])
print("reverse the string = ", animal[::-1])
# define/create a function
# the indented lines are part of the function
def convertFahrenheit2Celsius(fahrenheit):
celcius = 0.555 * (fahrenheit - 32)
return celcius
print('')
# and use the function
# (make sure you define/create the function before you call it)
print("A Fahrenheit to Celcius table:")
# range is from -40 to < 220 in steps of 10
for tf in range(-40, 220, 10):
print("%5.1fF = %5.1fC" % ( tf, convertFahrenheit2Celsius(tf) ))
print('')
print("A limited set:")
# another variation of the for loop
for tf in -40,0,32,98.6:
print("%5.1fF = %5.1fC" % ( tf, convertFahrenheit2Celsius(tf) ))
print('')
# test boolean results
print("Is 3 > 5? Result =", 3 > 5) # result = False
print("Is 3 < 5? Result =", 3 < 5) # result = True
# optional wait for keypress
input('Press Enter...')
Lardmeister
Posting Virtuoso
1,940 posts since Mar 2007
Reputation Points: 465
Solved Threads: 73
Skill Endorsements: 5
Thanks Ludwik! It needed to be updated after 8 years.
vegaseat
DaniWeb's Hypocrite
6,499 posts since Oct 2004
Reputation Points: 1,451
Solved Threads: 1,618
Skill Endorsements: 37