Lost Password?

Go Back   CodeCall Programming Forum > Software Development > Pascal/Delphi

Pascal/Delphi Forum for discussing Borland Delphi and Pascal coding techniques, tips and tricks.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old 01-23-2008, 09:41 PM
nolls nolls is offline
Newbie
 
Join Date: Jan 2008
Posts: 11
Rep Power: 0
nolls is on a distinguished road
Default

Thank you for all of the assistance void. Gladly appreciate it .
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 02-04-2008, 08:53 PM
nolls nolls is offline
Newbie
 
Join Date: Jan 2008
Posts: 11
Rep Power: 0
nolls is on a distinguished road
Default

Also, what exactly is Python used to create? I am having trouble coming up with some projects to create that will help me get a better understanding of python.

I don't know if this is because I don't know enough yet, but I also don't know what python is mostly used for. Once I do know, it might be easier for me to create some projects/benchmarks for me to acheive. Any help greatly appreciated.

Best regards
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 02-04-2008, 11:52 PM
v0id's Avatar   
v0id v0id is offline
Super Mod
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,007
Last Blog:
CherryPy(thon)
Rep Power: 21
v0id is just really nicev0id is just really nicev0id is just really nicev0id is just really nice
Send a message via MSN to v0id
Default

Python is used for a lot of different things. Everything from web-programming to GUI-programming. I think it's used most for small scripts to manage the system, though.

I think you shall just think about what you would like to make, and than start making it. You may need a third-party library, but fortunately there's a lot of those around. Personally, I like CherryPy, Cheetah and wxPython.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Finally we got that Python-forum!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 02-05-2008, 02:09 PM
nolls nolls is offline
Newbie
 
Join Date: Jan 2008
Posts: 11
Rep Power: 0
nolls is on a distinguished road
Default

I am not really clear on what purpose GUI serves. Is it basically the overall appearance of a program?

Now I am learning about functions and defining your own. Got past strings, tuples, lists, dictionaries, methods etc. So I am still a n00b to python and to programming in general. So with what I have learned so far is there much to create? I have been thinking of what else I could, but I am stumped.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 02-06-2008, 01:54 AM
v0id's Avatar   
v0id v0id is offline
Super Mod
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,007
Last Blog:
CherryPy(thon)
Rep Power: 21
v0id is just really nicev0id is just really nicev0id is just really nicev0id is just really nice
Send a message via MSN to v0id
Default

GUI means Graphical User Interface, so it's everything you're looking at. Like now, when you read this post you'll probably be reading it from a browser; this browser have a graphical user interface - it's everything you're looking at. As default, Python ships with Tkinter, so you could try out some GUI-programming right away, without installing new libraries.

From what you're saying you know, you should be able to make the famous guess-a-number-game. It requires you to have the basic understanding of modules and user I/O though.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Finally we got that Python-forum!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #16 (permalink)  
Old 02-26-2008, 09:39 PM
nolls nolls is offline
Newbie
 
Join Date: Jan 2008
Posts: 11
Rep Power: 0
nolls is on a distinguished road
Default

Ok, after coming back to learn Python I decided to try and write a guess-a-number game. Although, I don't know how to make the "number" be randomly assigned to a different number every guess. So I just designated the number 3 as the "number". How would I be able to make the number switch every time though?

Here is the code:
Code:
print "Welcome to the Guess a Number game"
print "Goal: To guess the number the computer is thinking of"
number = 0
while number != 6:
    print "1. Number 1"
    print "2. Number 2"
    print "3. Number 3"
    print "4. Number 4"
    print "5. Number 5"
    print "6. Exit"
    number = input("Which number would you like to guess? ")
    if number == 1:
        print "Nope! Try again"
    elif number == 2:
        print "Nope! Try again"
    elif number == 3:
        print "Yes, you guessed right!"
    elif number == 4:
        print "Nope! Try again"
    elif number == 5:
        print "Nope! Try again"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17 (permalink)  
Old 02-26-2008, 11:52 PM
v0id's Avatar   
v0id v0id is offline
Super Mod
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,007
Last Blog:
CherryPy(thon)
Rep Power: 21
v0id is just really nicev0id is just really nicev0id is just really nicev0id is just really nice
Send a message via MSN to v0id
Default

You can generate random numbers using the module random. There's lots of ways to use the module, so you may want to check out the documentation for all the information. This is an example on how it could be done:
Code:
import random

# Generate a number between 1 and 10 (including 1 and 10)
number = random.randint(1, 10)
You should consider modifying your code a little too. You've hardcoded all the possibilities, which is inefficient. I would rather compare the input with the random number.
Code:
# Check if the input is valid (1-10)
if input >= 1 and input <= 10:
    # Check if the input is greater than the random number
    if input > number:
        print "The random number is less than %d" % input
    # Check if the input is less than the random number
    elif input < number:
        print "The random number is greater than %d" % input
    # If non of the expressions above were true, it must be the right input.
    else:
        print "You guessed the right number, congratulations!"
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Finally we got that Python-forum!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #18 (permalink)  
Old 02-27-2008, 09:03 PM
nolls nolls is offline
Newbie
 
Join Date: Jan 2008
Posts: 11
Rep Power: 0
nolls is on a distinguished road
Default

Ok thanks for the advice void . Here is the new code:

Code:
import random
print "Welcome to the Guess a Number game"
print "Goal: To guess the number the computer is thinking of"
number = 0
while number != 6:
    compnum = random.randint(1, 5)
    print "1. Number 1"
    print "2. Number 2"
    print "3. Number 3"
    print "4. Number 4"
    print "5. Number 5"
    print "6. Exit"
    number = input("Which number would you like to guess? ")
    if compnum >= 1 and compnum <= 5:
        if compnum > number:
            print "Too low, try again"
        elif compnum < number:
            print "Too high, try again"
        elif compnum == number:
            print "You guessed the right number, congrats!"
I have some questions I would still like to ask though.

Does randint mean random integers? Wouldn't randrange work also (while looking into module random that was what randrange was said to do, integers between parameters)?

What did you mean by hardcode? And is this good enough or can it be modified further?

Oh and is a floating number just a decimal/integer? Forgot the meaning of it .

Last edited by nolls; 02-27-2008 at 09:12 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #19 (permalink)  
Old 02-27-2008, 11:58 PM
v0id's Avatar   
v0id v0id is offline
Super Mod
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,007
Last Blog:
CherryPy(thon)
Rep Power: 21
v0id is just really nicev0id is just really nicev0id is just really nicev0id is just really nice
Send a message via MSN to v0id
Default

You could probably use randrange too. I haven't played around with random for a long time, and the only function I remember was the one I used, randint.

You "hardcoded" every possible input, you thought you could get from the user. That's no a good way to do it, if you later want to extend your program. Let's say you were just going to add more random number possibilities.

Floating numbers are the numbers with fractional parts behind the decimal separator, like; 12.34, 1.34, 4353.2354, etc.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Finally we got that Python-forum!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Square root and calculator program!!! 123456789asdf C and C++ 10 12-02-2007 04:35 PM
A small Problem Timotay Python 2 10-18-2007 11:45 AM
need help with a small program scott0999 General Programming 5 03-01-2007 12:19 AM
A small problem in the output The_Master C and C++ 3 12-13-2006 12:04 PM


All times are GMT -5. The time now is 07:40 PM.

Contest Stats

Xav ........ 164.00000
dargueta ........ 128.00000
John ........ 127.00000
gaylo565 ........ 18.00000
XaNaX ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

Ads