Posted: Wed Apr 08, 2009 7:28 pm Post subject: My First Program!
This is my first Python script. I started Python yesterday and I just wanted the CompSci community to see it and evaluate it. The general idea of the calculator is thought of from another script written by someone else NOT me. I just added in a couple of more functions to the script, and it was originally started from scratch. Its not long or anything but I'm still somewhat proud of it . Please do tell me better ways I could have made this script(shorter...more efficient), and remember, criticism is encouraged!
Sponsor Sponsor
Sniper4Life
Posted: Wed Apr 08, 2009 7:29 pm Post subject: Re: My First Program!
No need to download...here is the code!
Python:
def options():
print"Welcome to Abrar's Program!" print" " print"1) Add numbers" print"2) Subtract numbers" print"3) Multiply a number" print"4) Divide a number" print"5) Use Exponents" print"6) Quit Program" print" "
Posted: Wed Apr 08, 2009 7:53 pm Post subject: RE:My First Program!
nice, looks familiar though
I'm thinking of writing a new game with pygame, maybe if it's any good i'll post it
Sniper4Life
Posted: Wed Apr 08, 2009 8:03 pm Post subject: Re: My First Program!
lol yes very familiar
i didnt copy and paste atleast
i remembered what i read
then learned to do it on my own
im gonna add more stuff to it later on?
like getting the square root...finding the circumference of a cirlce...radius of a circle...stuff like that
basic...easy...
anyways i could improve on it?
saltpro15
Posted: Wed Apr 08, 2009 8:05 pm Post subject: RE:My First Program!
well, the suggestions you made would be excellent, I would also recommend taking advantages of python's classes, which are very handy
Sniper4Life
Posted: Wed Apr 08, 2009 8:09 pm Post subject: Re: My First Program!
u mean actually taking python classes?
or the online resources available...???
and python is SOOO much easier than c++
man i was kind dumb to start with c++
btw salt...what age did you start coding?
and having an interest in computers
i asked wtd before but he nvr answered me
saltpro15
Posted: Wed Apr 08, 2009 8:33 pm Post subject: RE:My First Program!
no, I meant the class function in python, maybe wait a bit to get into that, it's sort of advanced. I started coding in October, I am currently programming in Turing,C++ and Python, I've always been interested in comp's though
EDIT
I'm 15, in Grade 10
Sniper4Life
Posted: Wed Apr 08, 2009 9:12 pm Post subject: RE:My First Program!
ok good to see you started at age 15
im 13 and i started in january
i thought i was sort of "late" to all possible good programmers because i have this one friend and he is PRO with programming
he's been writing scripts since he was 7 or 8 i think?
so ya....i thought i was like a complete noob
good to see i didnt start that late
Sponsor Sponsor
Analysis Mode
Posted: Wed Apr 08, 2009 10:13 pm Post subject: Re: My First Program!
Not bad. Python's a pretty good language.
You shold also try Pascal, always a good language to start with, easy to read, etc.
C++ should be your second or third language (it's my second), much more powerful, STL's, etc. you should know the basics of programming (variables, procedures/functions, loops, etc.) before moving onto C++. Knowing PAscal made it much easier to learn c++ in my case.
wtd
Posted: Wed Apr 08, 2009 11:54 pm Post subject: RE:My First Program!
Replace the test in the loop. You can more directly express this in the following form.
code:
while True:
if blah:
...
break
Also, your conditional has some other issues.
A) The input function returns a string. You check for equality against integers. What do you expect if I input 4 as my choice of options? Now, what actually happens?
B) Your conditional is not robust. What happens if I choose option 13? What should happen?
Sniper4Life
Posted: Thu Apr 09, 2009 6:21 am Post subject: Re: My First Program!
hehe wtd i noticed the thing you said too
the option 13 thing
see...problem is...i DONT KNOW how to do that efficiently...so THERES my problem...so could you tell me how i could do that?
and the
code:
while True:
if blah
***
break
what do you mean with it?
DemonWasp
Posted: Thu Apr 09, 2009 10:01 am Post subject: RE:My First Program!
I'll explain:
code:
while true // this means "loop forever, until I say break"
if blah // test for some condition. You have lots of these above; in particular, when it says function==6, you're setting "loop" to zero, meaning "stop looping"
break; // this means "stop looping right now"
Side note: How long before someone finally stamps a "Not for first-time coders" label on C++? That language is probably just about the worst thing for a new programmer - worse than Windows, worse than a bad teacher. It is the graveyard of new programmers.
Sniper4Life
Posted: Thu Apr 09, 2009 11:38 am Post subject: Re: RE:My First Program!
wtd @ Wed Apr 08, 2009 10:54 pm wrote:
Replace the test in the loop. You can more directly express this in the following form.
B) Your conditional is not robust. What happens if I choose option 13? What should happen?
k first...could anyone explain to me an EFFICIENT way of making any number over 6 do something specific?
using a loop or sumthing?
and btw demonwasp it doesnt really help improve the performance of the program...just the code itself?
[Gandalf]
Posted: Thu Apr 09, 2009 12:01 pm Post subject: RE:My First Program!
code:
elif function > 6:
saltpro15
Posted: Thu Apr 09, 2009 2:36 pm Post subject: Re: RE:My First Program!
Sniper4Life @ Wed Apr 08, 2009 wrote:
ok good to see you started at age 15
im 13 and i started in january
i thought i was sort of "late" to all possible good programmers because i have this one friend and he is PRO with programming
he's been writing scripts since he was 7 or 8 i think?
so ya....i thought i was like a complete noob
good to see i didnt start that late
you can really start whenever. It all depends on how well you take to programming. will you be in high school next year? if so, I recommend signing up for DWITE it's an excellent way to get experience in programming contests, Dan and Tony host it monthly October-February.