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


First program help - PrimeD - 02-22-2014

Thanks for taking the time to read this. I am teaching myself to use python. I get ADD sometimes so I need to do things to keep me learning and my attention focused on the goal. So I decided to try to program a madlib for my kids. I know this is may seem real simple but I am a little confused on one part. I am trying to take a age input and then make a function to make thier age look rediculous. I will post what I am working with. Everything else works except what I am trying to do with the age. I also am open to constructive feedback on if there are ways I do this properly/cleaner.
Thanks to Ex094 your article helped me get started.

Code:
#My first program using some of the basic skills I have learned from Ex094 #and "A Byte of Python" by Swaroop C H. #Wanted to try making a madlib for my kids. you = input('What is your name: ') #What i at trying to do is make my kids put in there age but when the madlib writes, #I want it to be rediculous #Below is what I am having a problem with age = input('How old are you: ') x = age y = 33 z = sum(x + y) 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, z, 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')



First program help - PrimeD - 02-22-2014

Thanks for taking the time to read this. I am teaching myself to use python. I get ADD sometimes so I need to do things to keep me learning and my attention focused on the goal. So I decided to try to program a madlib for my kids. I know this is may seem real simple but I am a little confused on one part. I am trying to take a age input and then make a function to make thier age look rediculous. I will post what I am working with. Everything else works except what I am trying to do with the age. I also am open to constructive feedback on if there are ways I do this properly/cleaner.
Thanks to Ex094 your article helped me get started.

Code:
#My first program using some of the basic skills I have learned from Ex094 #and "A Byte of Python" by Swaroop C H. #Wanted to try making a madlib for my kids. you = input('What is your name: ') #What i at trying to do is make my kids put in there age but when the madlib writes, #I want it to be rediculous #Below is what I am having a problem with age = input('How old are you: ') x = age y = 33 z = sum(x + y) 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, z, 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 - Ex094 - 02-22-2014

You can do it like this:

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

Instead of 33, you can generate any random number using Python b/w a given range hence on every run the age will look weirder depending upon the generated number.


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

You can do it like this:

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

Instead of 33, you can generate any random number using Python b/w a given range hence on every run the age will look weirder depending upon the generated number.


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

ok, i figured it out.
Code:
age = int(input('How old are you: ')) x = age y = 33 sum = x+y
This is what I did to get it to work. Still, are there better ways that I could acomplish what I did.

(02-22-2014, 08:40 PM)Ex094 Wrote: You can do it like this:

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

Instead of 33, you can generate any random number using Python b/w a given range hence on every run the age will look weirder depending upon the generated number.

Nice, i thought about getting random numbers in there but have not got that far in the book. Thanks for showing me how.


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

ok, i figured it out.
Code:
age = int(input('How old are you: ')) x = age y = 33 sum = x+y
This is what I did to get it to work. Still, are there better ways that I could acomplish what I did.

(02-22-2014, 08:40 PM)Ex094 Wrote: You can do it like this:

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

Instead of 33, you can generate any random number using Python b/w a given range hence on every run the age will look weirder depending upon the generated number.

Nice, i thought about getting random numbers in there but have not got that far in the book. Thanks for showing me how.


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

(02-22-2014, 08:43 PM)PrimeD Wrote: ok, i figured it out.
Code:
age = int(input('How old are you: ')) x = age y = 33 sum = x+y
This is what I did to get it to work. Still, are there better ways that I could acomplish what I did.

(02-22-2014, 08:40 PM)Ex094 Wrote: You can do it like this:

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

Instead of 33, you can generate any random number using Python b/w a given range hence on every run the age will look weirder depending upon the generated number.

Nice, i thought about getting random numbers in there but have not got that far in the book. Thanks for showing me how.

Correct! I too just figured out that you hadn't converted the input to int because the input by default is set as a string so you'll have to convert it to int before passing it on to the sum function. Using random can be much fun Biggrin


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

(02-22-2014, 08:43 PM)PrimeD Wrote: ok, i figured it out.
Code:
age = int(input('How old are you: ')) x = age y = 33 sum = x+y
This is what I did to get it to work. Still, are there better ways that I could acomplish what I did.

(02-22-2014, 08:40 PM)Ex094 Wrote: You can do it like this:

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

Instead of 33, you can generate any random number using Python b/w a given range hence on every run the age will look weirder depending upon the generated number.

Nice, i thought about getting random numbers in there but have not got that far in the book. Thanks for showing me how.

Correct! I too just figured out that you hadn't converted the input to int because the input by default is set as a string so you'll have to convert it to int before passing it on to the sum function. Using random can be much fun Biggrin


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

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?


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

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?