May-30-2018, 02:58 PM
In the book I'm learning python programming from, there is an exercise where I have to gain user input on their two favourite foods to create a name for a new food. Most of the code works, but I can't get the two food names to add together despite following the similar codes previously demonstrated in the book (which all worked fine) as best I can. Even if I put in numbers instead of words it doesn't work. I fear I am somehow missing something very simple, though it could be to do with the fact that book is written for Python 3.1, and I am using Python 3.6.5. This is the code I put in:
What is your favourite food? cheese
cheese
What is your second favourite food? cake
cake
new food:
Press the enter key to exit
Any help you can give me would be greatly appreciated, also, if you can tell me whether I got it wrong due to an oversight, or just because of the difference between python 3.1 and 3.6.5, that should be helpful in the way I approach other problems in the future. Thanks in advance for looking at my thread, and for any help you can give me.
Stephen.
food1 = input("What is your favourite food? ") print("food1") food2 = input("What is your second favourite food? ") print("food2") newfood = food1 + food2 print("\nnewfood:") input("\n\nPress the enter key to exit")If I were to put cheese as the favourite food, and cake as the second favourite it should create a "newfood" and come out with either cheesecake, or cheese cake (but I think it would be the first). What I actually get is:
What is your favourite food? cheese
cheese
What is your second favourite food? cake
cake
new food:
Press the enter key to exit
Any help you can give me would be greatly appreciated, also, if you can tell me whether I got it wrong due to an oversight, or just because of the difference between python 3.1 and 3.6.5, that should be helpful in the way I approach other problems in the future. Thanks in advance for looking at my thread, and for any help you can give me.
Stephen.