![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Expert Programmer
|
I like IR's idea of fucntions for writing data. You could write some functions to write the data of your power program you are creating.
|
|
|
|
|
|
#12 |
|
Programmer
Join Date: Apr 2005
Location: Uk
Posts: 68
Rep Power: 4
![]() |
ohh i get it, so it must be
print 2**x and the sums of it look right now.. |
|
|
|
|
|
#13 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Congrats.
Well from what I can tell your knowledge of Python's commands looks standard, but you just need a bit more exercise in the thinking process of programming. See what you can do with the Primes. I'll be on drsane_@hotmail.com if you wish for help. Edit: Actually...it's past 11. I better be going to bed. I'll still be willing to help, I just need some sleep. Later. Last edited by Sane; Apr 13th, 2005 at 10:14 PM. |
|
|
|
|
|
#14 |
|
Programmer
Join Date: Apr 2005
Location: Uk
Posts: 68
Rep Power: 4
![]() |
Prime Numbers is;
number = input("> ")
dif = number % 2
if dif != 0 :
print number, "Is a prime"
if dif == 0 :
print number, "is not a prime"is that right, or am i barking up the wrong tree again, lol. thanks for you help Sane |
|
|
|
|
|
#15 |
|
Expert Programmer
|
Speaking of writing to a disk, I just wrote a small script recently to get catorgize my collection of mp3s since they're scattered all thoughout differnt folders. If you decide to to any IO functions, this is a good example of a practical program.
import os
x = os.listdir("c:/Documents and Settings/Frazier PH&A/Desktop/Anthony's Files/Music")
thing = open("music.txt","w")
for y in x:
print y
thing.write(y+"\n")
thing.close()
x = os.listdir("c:/Documents and Settings/Frazier PH&A/Desktop/Anthony's Files/Random")
thing = open("music.txt","a")
for y in x:
print y
thing.write(y+"\n")
thing.close()
x = os.listdir("c:/Documents and Settings/Frazier PH&A/Desktop/Anthony's Files/Random/k")
thing = open("music.txt","a")
for y in x:
print y
thing.write(y+"\n")
thing.close()
x = os.listdir("c:/Documents and Settings/Frazier PH&A/Desktop/Anthony's Files/Random/k/k")
thing = open("music.txt","a")
for y in x:
print y
thing.write(y+"\n")
thing.close()And also SaturN, the only problem with your prime program is it doesn't test for primes, it only test to see if a program is even or odd, but you're on the right track. Each number is only prime if it isn't divisible by any number less than it. Last edited by thechristelegacy; Apr 13th, 2005 at 10:58 PM. |
|
|
|
|
|
#16 |
|
Programmer
Join Date: Apr 2005
Location: Uk
Posts: 68
Rep Power: 4
![]() |
I see your point..
![]() I never was good at math.. lol |
|
|
|
|
|
#17 |
|
Expert Programmer
|
Hey it's all good man. I'm not that smart when it comes to math either.
|
|
|
|
|
|
#18 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
I'm one of those mathy guys, so I help people with math. ^_^
A little nudge on the right tracK: Primes are only equally divisble by one and itself. if x%x==0 if x%1==0 (the 0 and 1 could be represented by constant variables) And all other numbers in between are not. if x%x-1!=0 if x%x-2!=0 etc... if x%2!=0 (the (x-1), (x-2), are therefore dependents on the variable x) It wouldn't be a good idea to do x-1 for the dependents though, there are many reasons why that could create a poorly consistent program. There's a very reasonable and efficient way that I'll see if you can think up by yourself. =P |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|