Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    2
    ReputationRep:
    Hello, I am relatively new to Python and would appreciate some help. I am making a quiz. Each person playing gets a score that goes up or down depending on the number of questions they answer incorrectly or correctly. Depending on how well the person plays they will have a different score.

    How can I say:

    print Score

    but not as a string "Score" as the numeric value of the variable Score?

    Please help,

    Thanks
    Offline

    17
    ReputationRep:
    Code:
    score = 1337
    print score
    It's as simple as that in python. However, if this is a GUI application you're developing then you'd need to set the text property of the GUI component to the value of score, and that I do not know how to do since I do not specialise in python. Often, googling your questions will yield an answer.
    • Thread Starter
    Offline

    2
    ReputationRep:
    (Original post by Async)
    Code:
    score = 1337
    print score
    It's as simple as that in python. However, if this is a GUI application you're developing then you'd need to set the text property of the GUI component to the value of score, and that I do not know how to do since I do not specialise in python. Often, googling your questions will yield an answer.
    Thanks

    Also, could you help me again?

    How can I let my program wait a little before closing.

    I want my player to be able to see their end score before they end but instead the program ends instantly.
    Offline

    17
    ReputationRep:
    (Original post by The Awakener)
    Thanks

    Also, could you help me again?

    How can I let my program wait a little before closing.

    I want my player to be able to see their end score before they end but instead the program ends instantly.
    Usually you'd use a timer for this sort of thing. But again I'm not specialised in python so I cannot help there.
    • TSR Support Team
    • Clearing and Applications Advisor
    Offline

    21
    ReputationRep:
    (Original post by The Awakener)
    Thanks

    Also, could you help me again?

    How can I let my program wait a little before closing.

    I want my player to be able to see their end score before they end but instead the program ends instantly.
    Doesn't it just print the answer to the terminal? I don't see why the message would go away when the program finishes executing.
    Offline

    1
    ReputationRep:
    (Original post by The Awakener)
    Thanks

    Also, could you help me again?

    How can I let my program wait a little before closing.

    I want my player to be able to see their end score before they end but instead the program ends instantly.
    If you want to put a delay after your end score has been outputted, you need to import the time module at the start.
    Then, after the score has been outputted insert the code time.sleep(x)
    [Replace X with a numeric value of your choosing, X being the number of seconds the delay lasts for]
    Offline

    7
    ReputationRep:
    Yep, the above solution is valid.

    The time.sleep() function is the best way to go about it.

    You need to ensure you call upon the 'time' module also.
    Code:
    import time
    time.sleep(5)
    would sleep the script for 5 seconds.

    Another tactic i've used for preserving the data in the 'python.exe' if its being ran is simply declaring a variable at the end eg.
    Code:
    n = input("Please exit Python")
    This is obviously dependent on how the program is being run, if its being run in the Python GUI (IDLE) the data stays on the screen.
    If its the Python.exe or simply 'opening' the script - what I put above would suffice.
    Offline

    3
    ReputationRep:
    (Original post by The Awakener)
    Thanks

    Also, could you help me again?

    How can I let my program wait a little before closing.

    I want my player to be able to see their end score before they end but instead the program ends instantly.
    At the very top type "import time", whenever you want to delay type "time.sleep(1)".

    The number inside the bracket is how many seconds you want to pause for.
    Offline

    18
    ReputationRep:
    I'm extremely new to python and programming in general so others can probably provide a better answer, but I think assign the score in a function and use 'return' instead of 'print'.

    Then callling the function at a later point in the program would be a solution??
    Offline

    17
    ReputationRep:
    (Original post by CyberJake)
    Yep, the above solution is valid.

    The time.sleep() function is the best way to go about it.

    You need to ensure you call upon the 'time' module also.
    Code:
    import time
    time.sleep(5)
    would sleep the script for 5 seconds.

    Another tactic i've used for preserving the data in the 'python.exe' if its being ran is simply declaring a variable at the end eg.
    Code:
    n = input("Please exit Python";)
    This is obviously dependent on how the program is being run, if its being run in the Python GUI (IDLE) the data stays on the screen.
    If its the Python.exe or simply 'opening' the script - what I put above would suffice.
    Your solution is NOT the best way to go about it, I don't know python as well but I am assuming calling time.sleep(5) will freeze the UI thread, meaning the whole program will become unresponsive which is bad practise. You should spawn a different thread and freeze that thread, leaving the UI thread response, so users can still interact with the parts that should be unaffected by the time.sleep() function.
    Offline

    19
    ReputationRep:
    (Original post by The Awakener)
    Thanks

    Also, could you help me again?

    How can I let my program wait a little before closing.

    I want my player to be able to see their end score before they end but instead the program ends instantly.
    A much easier way is to implement a "Press enter to escape"
    which would be implemented through the code:
    input("Press Enter to Escape")
    Ignore the parenthesis if you're running python 2.
    Offline

    3
    ReputationRep:
    (Original post by Async)
    Your solution is NOT the best way to go about it, I don't know python as well but I am assuming calling time.sleep(5) will freeze the UI thread, meaning the whole program will become unresponsive which is bad practise. You should spawn a different thread and freeze that thread, leaving the UI thread response, so users can still interact with the parts that should be unaffected by the time.sleep() function.
    If the program is exiting immediately after the execution has completed it's obviously running in a terminal...
    Offline

    17
    ReputationRep:
    (Original post by Push_More_Button)
    If the program is exiting immediately after the execution has completed it's obviously running in a terminal...
    Op did not state if the program is a GUI or a CLI, therefore we can both assume what we want. I was assuming it was a GUI application because of the nature of the task.
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    Are unpaid trial work shifts fair?
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.