I'm learning about functions in Python 2.7.x and one of the suggestions in the book I am using is to solicit input from a user to get values for the script. The advice on how to use raw_input
in a function is as follows:
You need to use int() to convert what you get from raw_input()
I'm not sure how to use int()
yet. This is what I have tried so far:
def cheeses_and_crackers(cheeses, crackers):
print "You have %d types of cheeses." % cheeses
print "You have %d types of crackers." % crackers
print "That is a lot of cheese and crackers!\n"
print "How many cheeses do you have?"
cheeses1 = raw_input("> ")
int(cheeses1)
print "How many types of crackers do you have?"
crackers1 = raw_input("> ")
int(crackers1)
cheeses_and_crackers(cheeses1, crackers1)
The error I get when I try run this is as follows:
TypeError: %d format: a number is required, not str
I'm guessing how to use int()
so I'd appreciate some help with basic syntax too.