An interactive introduction to programming in Python, for human beings and whoever else
Chapter 11
I’d like to experience new and amazing kinds of animal sounds, so let’s learn a new function called input. Click run to see what happens!
sound = input("What sound does the animal make?")
if sound == 'meow meow':
print("It's a cat!")
We can use input to ask the user questions, and the part in quotes is what your prompt is. Then you get to save the answer into a variable!
Try running the code several times, answering with different animal sounds. If you say meow meow Python will tell you it’s a cat, but if you say anything else she won’t!
Let’s practice with input a little bit. The mission:
nameif statement for this one, it’s just practice for inputinput with “What’s your name?”namename = prompt("What's your name?")print with multiple things by using commas, like print("I ate", 55, "bananas")print("Hello", name)Okay, we proved that we’re friendly, so let’s get on to the next chapter and put input to use!
We learned to ask for input from the user by using input.