Sinisterly
First program help - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Python (https://sinister.ly/Forum-Python)
+--- Thread: First program help (/Thread-First-program-help)

Pages: 1 2 3


RE: First program help - Ligeti - 02-22-2014

(02-22-2014, 08:53 PM)PrimeD Wrote: I tried adding random but for the following error

line 11, in <module>
weird = random.randint(1, 100)
NameError: name 'random' is not defined

Code:
age = int(input('How old are you: ')) weird = random.randint(1, 100) oldage = sum(age + weird)

what did I do wrong?

you need to import random library, just add this at the top of your code:
Code:
import random

Happy Coding


RE: First program help - Ligeti - 02-22-2014

(02-22-2014, 08:53 PM)PrimeD Wrote: I tried adding random but for the following error

line 11, in <module>
weird = random.randint(1, 100)
NameError: name 'random' is not defined

Code:
age = int(input('How old are you: ')) weird = random.randint(1, 100) oldage = sum(age + weird)

what did I do wrong?

you need to import random library, just add this at the top of your code:
Code:
import random

Happy Coding


RE: First program help - PrimeD - 02-22-2014

(02-22-2014, 09:57 PM)Ligeti Wrote:
(02-22-2014, 08:53 PM)PrimeD Wrote: I tried adding random but for the following error

line 11, in <module>
weird = random.randint(1, 100)
NameError: name 'random' is not defined

Code:
age = int(input('How old are you: ')) weird = random.randint(1, 100) oldage = sum(age + weird)

what did I do wrong?

you need to import random library, just add this at the top of your code:
Code:
import random

Happy Coding

Thanks, got it to work. Thanks to everybody for the help. I will show the final product for constructive feedback
Code:
#My first program using some of the basic skills I have learned from Ex094 #and "A Byte of Python" by Swaroop C H. you = input('What is your name: ') age = int(input('How old are you: ')) import random weird = random.randint(1, 100) sum = (age + weird) family = input('What is the name of a family member: ') animal = input('Choose a animal: ') verb = input('Pick a verb: ') noun = input('Choose a noun: ') word = input('Pick a random word: ') print('One day {} who is {} years old, was playing at the park with {}'.format(you, sum, family)) print('When all of a sudden a giant {} jumped out of the bushes and said {}'.format(animal, word)) print('They were so shocked that they tripped over a {} and yelled {}'.format(noun, verb)) s = input('Did you laugh?: ') if s == 'yes': print('Your funny') if s == 'no': print('Should have picked funnier words')



RE: First program help - PrimeD - 02-22-2014

(02-22-2014, 09:57 PM)Ligeti Wrote:
(02-22-2014, 08:53 PM)PrimeD Wrote: I tried adding random but for the following error

line 11, in <module>
weird = random.randint(1, 100)
NameError: name 'random' is not defined

Code:
age = int(input('How old are you: ')) weird = random.randint(1, 100) oldage = sum(age + weird)

what did I do wrong?

you need to import random library, just add this at the top of your code:
Code:
import random

Happy Coding

Thanks, got it to work. Thanks to everybody for the help. I will show the final product for constructive feedback
Code:
#My first program using some of the basic skills I have learned from Ex094 #and "A Byte of Python" by Swaroop C H. you = input('What is your name: ') age = int(input('How old are you: ')) import random weird = random.randint(1, 100) sum = (age + weird) family = input('What is the name of a family member: ') animal = input('Choose a animal: ') verb = input('Pick a verb: ') noun = input('Choose a noun: ') word = input('Pick a random word: ') print('One day {} who is {} years old, was playing at the park with {}'.format(you, sum, family)) print('When all of a sudden a giant {} jumped out of the bushes and said {}'.format(animal, word)) print('They were so shocked that they tripped over a {} and yelled {}'.format(noun, verb)) s = input('Did you laugh?: ') if s == 'yes': print('Your funny') if s == 'no': print('Should have picked funnier words')



RE: First program help - chmod - 02-22-2014

I usually like to have imported modules at the start of the program (just after your comments and before the variables) and leave a couple of blank lines between the comments, modules, variables and code. It just makes it a little easier to read especially when you come back to it down the line to improve it or add some other features. All in all though not a bad attempt the one thing I will suggest though is to convert the users input to a string rather than having to use "'s around the inputed text.

EDIT:
Ignore that last part about strings I was running the script in 2.7 when this is clearly designed for 3. When using the correct interpreter it run fine *facepalm*


RE: First program help - chmod - 02-22-2014

I usually like to have imported modules at the start of the program (just after your comments and before the variables) and leave a couple of blank lines between the comments, modules, variables and code. It just makes it a little easier to read especially when you come back to it down the line to improve it or add some other features. All in all though not a bad attempt the one thing I will suggest though is to convert the users input to a string rather than having to use "'s around the inputed text.

EDIT:
Ignore that last part about strings I was running the script in 2.7 when this is clearly designed for 3. When using the correct interpreter it run fine *facepalm*


RE: First program help - PrimeD - 02-22-2014

(02-22-2014, 11:22 PM)chmod Wrote: I usually like to have imported modules at the start of the program (just after your comments and before the variables) and leave a couple of blank lines between the comments, modules, variables and code. It just makes it a little easier to read especially when you come back to it down the line to improve it or add some other features. All in all though not a bad attempt the one thing I will suggest though is to convert the users input to a string rather than having to use "'s around the inputed text.

EDIT:
Ignore that last part about strings I was running the script in 2.7 when this is clearly designed for 3. When using the correct interpreter it run fine *facepalm*

Thanks for the input. I am thinking that I should just use this and build on it as I learn more. The next portion of Ex094's tutorial talks about list. Once I get a grasp on that, adding those functions on there.

Ex094: Thanks for the random number idea. My 14 son was "wait I am not 91 years old, i did not put 91 in there." It through them both for a loop.


RE: First program help - PrimeD - 02-22-2014

(02-22-2014, 11:22 PM)chmod Wrote: I usually like to have imported modules at the start of the program (just after your comments and before the variables) and leave a couple of blank lines between the comments, modules, variables and code. It just makes it a little easier to read especially when you come back to it down the line to improve it or add some other features. All in all though not a bad attempt the one thing I will suggest though is to convert the users input to a string rather than having to use "'s around the inputed text.

EDIT:
Ignore that last part about strings I was running the script in 2.7 when this is clearly designed for 3. When using the correct interpreter it run fine *facepalm*

Thanks for the input. I am thinking that I should just use this and build on it as I learn more. The next portion of Ex094's tutorial talks about list. Once I get a grasp on that, adding those functions on there.

Ex094: Thanks for the random number idea. My 14 son was "wait I am not 91 years old, i did not put 91 in there." It through them both for a loop.


RE: First program help - Ex094 - 02-23-2014

(02-22-2014, 11:44 PM)PrimeD Wrote:
(02-22-2014, 11:22 PM)chmod Wrote: I usually like to have imported modules at the start of the program (just after your comments and before the variables) and leave a couple of blank lines between the comments, modules, variables and code. It just makes it a little easier to read especially when you come back to it down the line to improve it or add some other features. All in all though not a bad attempt the one thing I will suggest though is to convert the users input to a string rather than having to use "'s around the inputed text.

EDIT:
Ignore that last part about strings I was running the script in 2.7 when this is clearly designed for 3. When using the correct interpreter it run fine *facepalm*

Thanks for the input. I am thinking that I should just use this and build on it as I learn more. The next portion of Ex094's tutorial talks about list. Once I get a grasp on that, adding those functions on there.

Ex094: Thanks for the random number idea. My 14 son was "wait I am not 91 years old, i did not put 91 in there." It through them both for a loop.

Anytime, well I'm sorry that I forgot to mention the "Import random" header. I see one thing that you've imported the random library between the code. Well it's a good practice and recommended one that always have it on the top of the code i.e.

Code:
import random ...Your code here



RE: First program help - Ex094 - 02-23-2014

(02-22-2014, 11:44 PM)PrimeD Wrote:
(02-22-2014, 11:22 PM)chmod Wrote: I usually like to have imported modules at the start of the program (just after your comments and before the variables) and leave a couple of blank lines between the comments, modules, variables and code. It just makes it a little easier to read especially when you come back to it down the line to improve it or add some other features. All in all though not a bad attempt the one thing I will suggest though is to convert the users input to a string rather than having to use "'s around the inputed text.

EDIT:
Ignore that last part about strings I was running the script in 2.7 when this is clearly designed for 3. When using the correct interpreter it run fine *facepalm*

Thanks for the input. I am thinking that I should just use this and build on it as I learn more. The next portion of Ex094's tutorial talks about list. Once I get a grasp on that, adding those functions on there.

Ex094: Thanks for the random number idea. My 14 son was "wait I am not 91 years old, i did not put 91 in there." It through them both for a loop.

Anytime, well I'm sorry that I forgot to mention the "Import random" header. I see one thing that you've imported the random library between the code. Well it's a good practice and recommended one that always have it on the top of the code i.e.

Code:
import random ...Your code here