(03-04-2014, 01:05 PM)Deque Wrote: (03-04-2014, 07:17 AM)PrimeD Wrote: OK, not sure what is wrong here. Looking at the guides it should work. here is the code and the error I get.
The focus in this portion of the project was learing how to use if, elif, and else. The if and else statements work. Just can not figure out the elif.
Code:
if number == mnumber:
print('Drats foiled again, you can leave!')
elif number < mnumber:
print('The monster laughed and said: I am going to enjoying having you for lunch!')
else:
print('Yummy Yummy Yummy, get in my tummy!')
Error recieved:
elif number < mnumber:
TypeError: unorderable types: str() < int()
thanks in advance.
PS. This will be the last part of the project.
Your error is a type problem. number is a string, while mnumber is an integer and the compiler complains that it can not compare them with <.
You need to convert number to an integer as well.
Thanks that fixed it. Ok here is the final product.
Code:
#My first program using some of the basic skills I have learned from Ex094
#and "A Byte of Python" by Swaroop C H.
import random
you = input('Hi, What is your name: ')
print('Hi! {} would you like me to tell you a story? Yes or No.'.format(you))
guess = input('How about it? ')
if guess == "no":
print('You are not fun at all!')
exit()
elif guess == "yes":
print('That is great! Let me ask you a few questions. ')
else:
print('Yes or No Please.')
age = int(input('How old are you: '))
if age > 13:
print("Aren't you a little old for MADLIB's?")
else:
print('Just the right age')
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: ')
monsters = ['Dracula ', 'Frankenstein ', 'the swamp man ', 'a warewolf ', 'the mummy ']
rand_item = random.choice(monsters)
weapon = ['pan ', 'knife ', 'boquet of flowers ', 'cream pie ']
rweapon = random.choice(weapon)
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 being followed by {}holding a {}and said {}.'.format(animal, rand_item, rweapon, word))
print('You were so shocked that you tripped over a {} and yelled {}'.format(noun, verb))
print('\nYou are told that you must battle to the death by a number guessing game.')
print('You will each guess a number between 1 and 10. If you guess the number behind my back, you will live.')
print('If you guess wrong we eat you and {}!'.format(family))
print('\n {} you go first.'.format(you))
number = input('What number do you chose? ')
mnumber = random.randint(1,10)
print('My number is {}.'.format(mnumber))
if number == mnumber:
print('Drats foiled again, you can leave!')
elif int(number) < int(mnumber):
print('The monster laughed and said: I am going to enjoying having you for lunch!')
elif int(number) > int(mnumber):
print('Yummy Yummy Yummy, get in my tummy!')
print('\nWhile you were being eaten, {} was able to run away.'.format(family))
print('The End')
s = input('Did you laugh?: ')
if s == 'yes':
print('Your funny')
if s == 'no':
print('Should have picked funnier words')
I know there are acouple things that need to be solved. Like, if someone enters anything other than yes or no. That is just beyond my level of knowledge. One day.
Now I need to think of a new project to build onto these lessons learn. I am open to any challenges that would help me to the next level.
Thanks again to everyone to helped.