Python help

For questions about using Classic.

Post » Thu Feb 07, 2008 7:32 am

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.
B
2
G
4
Posts: 13
Reputation: 1,076

Post » Thu Feb 07, 2008 9:14 am

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.
B
1
S
1
G
5
Posts: 8
Reputation: 1,391

Post » Thu Feb 07, 2008 10:56 am

thanks for your help :)
B
2
G
4
Posts: 13
Reputation: 1,076

Post » Thu Feb 07, 2008 11:02 am

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.
B
2
S
2
G
5
Posts: 108
Reputation: 1,866


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests