An interactive introduction to programming in Python, for human beings and whoever else
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:
ifstatement for this one, it’s just practice for
inputwith “What’s your name?”
name = prompt("What's your name?")
print("I ate", 55, "bananas")
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