Week 1

Print & Input

Make the computer show output with print(), and ask the user questions with input().

print()stringsinput()reading errors

Reference

print() displays output

print("Hello, world!")

Shows: Hello, world! Each print() shows up on its own line.

Strings are text in quotes

"pizza"
"I love coding!"
"( ^_^ )"

Quotes always come in pairs: one to start, one to end.

input() asks a question

name = input("What is your name? ")
print("Hi " + name)

The program waits for the user to type and press Enter. Leave a space at the end of your question.

+ joins strings

print("My name is " + "Maya")

Shows: My name is Maya. Forget the space and you get “My name isMaya”.

Common bugs

Print("hi")

NameError. Use a lowercase p.

print("hi)

SyntaxError. Close the quote.

print("hi"

SyntaxError. Close the parenthesis.

print(hi)

NameError. Text needs quotes.

Practice

Edit the code, press Run, and check the output.

Exercise 1

Say hello

Change the code so it prints your name on one line and your favorite food on the next.

Exercise 2

Bug hunt

This code has two bugs. Run it, read the error, and fix it until it works.

Exercise 3

Build a chatbot

Add at least two more questions, and make the program reply to each answer.

Vocab

Output · what your program shows Function · a command like print() String · text in quotes Bug · a mistake in code Debugging · finding and fixing bugs