Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

updated Guessing game source code, check it out

I updated my last Guessing game source code please check it out and tell me what you think, if it is good can you suggest another beginner project to work on to gain more experience.
Code
import time
import random

def StartGame():
    print "Welcome to the Guessing game"
    print "You will have to guess a number between 0 and 6"
    global num, time_s
    num = random.randint(0,6)
    time_s = time.time()
    return



def Loop():
    answer = False
    while answer == False:
        userinput = int(raw_input("What is your guess? "))
        if (num == userinput):
            print "Correct!"
            answer = True
            global time_e
            time_e = time.time()
        elif (userinput < num):
            print "Your guess is too low"
        elif (userinput > num):
            print "Your guess is too high"
    return



def HighScore():
    global time_t
    time_t = str(int(time_e - time_s))
    print "It took you " + time_t + " seconds. Can you beat your last score"
    return

def PlayAgain():
    close = False
    while close == False:
        again = raw_input("Press 1 if you want to play again or 2 to exit: ")
        again = int(again)
        if (again == 1):
            StartGame()
            Loop()
            HighScore()
            PlayAgain()
        elif (again == 2):
            print "GoodBye"
            close = True
    return


StartGame()
Loop()
HighScore()
PlayAgain()

-Jekwa
(Jul 25, 2013 11:44 PM)Jekwa Wrote:  if it is good can you suggest another beginner project to work on to gain more experience.

Looks great, keep up the good work and you'll be a great programmer soon enough!

Here's one beginner exercise I came across when I was teaching myself python:

[Image: FVNScos.png]


Bonus mode: expand that example to make a square of any size defined by the user!

[Image: 2wAf2IN.gif]
(Jul 26, 2013 12:39 AM)Emylbus Wrote:  Here's one beginner exercise I came across when I was teaching myself python:

Shameless advertisement:

A series of problems like these, as well as a proper checking system for the code, sadly, it has a cost, but what is a few dollars for knowledge :P

https://groklearning.com/challenge

recommend intermediate, if new to programming, but fancy yourself to be good at maths. Will teach you a lot more about thinking logically to solve problems, and there is help from some uni students during the comp (starts next week)

[spoiler]why is it that I think noone will actually bother with this on HF, cheap bastards...[/code]
yuhuu playing with functions ✌
👍 Very nicely done mate :)
(Jul 26, 2013 12:39 AM)Emylbus Wrote:  Looks great, keep up the good work and you'll be a great programmer soon enough!

Here's one beginner exercise I came across when I was teaching myself python:

[Image: FVNScos.png]


Bonus mode: expand that example to make a square of any size defined by the user!
Will try to do this project, Thank you
-Jekwa


(Jul 26, 2013 02:07 AM)我是欧米茄 Wrote:  yuhuu playing with functions ✌
👍 Very nicely done mate :)

Thank you Nixie, hopefully I can add more while learning and you can tell me what you think of them.

-Jekwa


(Jul 26, 2013 01:28 AM)Dmaster_773 Wrote:  Shameless advertisement:

A series of problems like these, as well as a proper checking system for the code, sadly, it has a cost, but what is a few dollars for knowledge :P

https://groklearning.com/challenge

recommend intermediate, if new to programming, but fancy yourself to be good at maths. Will teach you a lot more about thinking logically to solve problems, and there is help from some uni students during the comp (starts next week)

[spoiler]why is it that I think noone will actually bother with this on HF, cheap bastards...[/code]

Going to check your link out, Thanks for the share.

-Jekwa


(Jul 26, 2013 12:39 AM)Emylbus Wrote:  Looks great, keep up the good work and you'll be a great programmer soon enough!

Here's one beginner exercise I came across when I was teaching myself python:

[Image: FVNScos.png]


Bonus mode: expand that example to make a square of any size defined by the user!
I did the bonus mode, since from the bonus mode I can easily make number 1 and 2. Let me know what you think.
Code
def NormalPlus():
    print "+"
    return

def LinePlus():
    print "+",
    return

def NormalBreak():
    print "/"
    return

def LineBreak():
    print "/",
    return

def Row():
    print "- " *4,
    return

def Column():
    print "  " * 4,
    return

def Make():
    global userinput
    userinput = int(raw_input("How many rows? "))
    global userinput2
    userinput2 = int(raw_input("How many columns? "))
    MakeLine()
    for i in range(userinput2):
  MakeColumn()
  MakeLine()
    return

def MakeLine():
    if userinput == 1:
  LinePlus()
  Row()
  NormalPlus()
    elif userinput > 1:
  for i in range(userinput):
    LinePlus()
    Row()
  NormalPlus()
    return

def MakeColumn():
    if userinput2 == 1:
  for i in range(4):
    LineBreak()
    Column()
    NormalBreak()
    elif userinput2 > 1:
  for i in range(4):
    LineBreak()
    for i in range((userinput2 - 1)):
    Column()
    LineBreak()
    Column()
    NormalBreak()
    return

Make()

-Jekwa


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by MalentorJul 10, 2017 05:53 AM 6 234 Jul 10, 2017 05:53 AM
Last Post: Ensky
[C#] by MrJamieMcCOct 19, 2016 05:34 AM 57 2,239 Oct 19, 2016 05:34 AM
Last Post: Pim Fortuyn
[Python] by DataDumperMay 12, 2016 07:09 AM 1 93 May 12, 2016 07:09 AM
Last Post: SIM-1866423