|
||||||
| Pascal/Delphi Forum for discussing Borland Delphi and Pascal coding techniques, tips and tricks. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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 |
|
|||||
|
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! |
|
|||
|
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. |
|
|||||
|
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! |
| Sponsored Links |
|
|
|
|||
|
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"
|
|
|||||
|
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) 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! |
|
|||
|
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!"
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. |
|
|||||
|
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! |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |