0 Favourites

Python help

This forum is currently in read-only mode.
  • I have been doing python, and im not that great at it, but am trying to learn the ins and outs.

    im having a problem with some code, this is what i want;

    *user inputs some information after a question* this is an interger under a word... here's some code to explain:

    aaoc=raw_input("enter your selection, between 1-9:")

    I then want to do something like the following...

    import random

    random.randint(1,aaoc)

    I'm sure you can see what im trying to do, simply give the user a range option on a random output.

    I've never really understood the conversions, I'm guessing ill need to add some "str" somewhere, I've tried a few spots and none work.

    Thanks in advance, having this answered if possible will clear ALOT up for me, because int and str functions i never actually caught onto when in class.

    • maev

    p.s my programming jargon sucks, so i probably look silly, hope you don't mind

    edit: i also realize this isn't really a spot to ask python support, but i've seen some of the stuff some of you have said regarding python and you all seem quite knowledgeable, and im unsure where else to ask.

  • Use "input" rather than "raw_input", as raw_input will always give you a string.

    aaoc = input("enter your selection, between 1-9:")

    Then you can use this to verify the input:

    assert(type(aaoc) is int and 1 <= aaoc <= 9)

    This verifies that aaoc is an int and is a value between 1 and 9.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • thanks for your help

  • Ahhh Python.

    I will have to sit down and learn all the syntaxical nuances with the language sometime.

    Its good to know some of you guys here are well-versed in it already.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)