Support Forums
My First Codes - Any Views? - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Python Programming Language (https://www.supportforums.net/forumdisplay.php?fid=32)
+---- Thread: My First Codes - Any Views? (/showthread.php?tid=14787)



My First Codes - Any Views? - JamieMiller - 12-20-2010

I started teaching myself python a mouth ago, one of the first things I did was make a profit calculator. I coded some other things like a Mock Up 1980's computer and things like that. Does anyone know where I can get a list of tasks to try? ?

Oh i nearly forgot, here the code i made :-

x = raw_input ("Enter name: ")
print "Hey there " + x + " welcome to my profit calculator"
a = input ("Enter Sale Price: ")
b = input ("Enter Expenditure: ")
p = a - b
print p
print " Thank you for using my calculator " + x

I also made this one too :-

x = raw_input ("Enter Full Name ")
y = raw_input ("Enter Age ")
z = raw_input ("Enter Date of Birth ")
a = raw_input ("Enter Secure Number ")
n = "Press c, For Command Lists"

print "Verifing in process"

print x
print y
print z
print a

print "Corfirm Listed Deatails :- as yes or no"



yes = "ACCESS GRANTED TO " + x
no = "Restart System"
print n

c = " Select from the following :- m - upcomming missions / w - weapons / p - planes "
m = " ACCESS DENIED"
w = "ACCESS DENIED"
p = "Airbus A380 Shecdulded to arrive 4/11/10"

These were just from trial and error and some ideas a link to a list of commands would also be great Big Grin


RE: My First Codes - Any Views? - Thyonic - 01-03-2011

They look great for a beginner, but I'd look into using more of the Libraries that Python offers.


RE: My First Codes - Any Views? - Dubstep - 04-20-2011

There are quite a few things that could drastically improve your code. First of all, if you want someone to type something, then if they type a certain word or phrase or letter, do this.
Code:
example = raw_input("Type anything you want :")
if example == "hello":
        print "Hi sir"
What this code does, it says, Type anything you want:. If you type hello, it will print "Hi sir". If you want to make it a continuous loop, you would do:


Code:
while True:
       example = raw_input("Type anything you want: :")
       if example == "hello":
               print "Hi Sir"
       if example == "quit":
               break
Now, This code does the exact same thing, except if you type in anything in the previous code, and hit enter, the program would end. With a loop, the program keeps going on. If you were to use this one, it would keep asking you, Type anything you want:. If you were to type quit, then the program would end.

Here is an example of your code that I just made.
http://pastie.org/1818003

Feel free to use it for whatever you feel like. You should research on loops, and raw_input. Also if you want to get more advanced, use functions like I did. If you want me to explain what I did in the code I wrote, just post back here or feel free to PM me.