1 of 38

Input and Output (I/O)

Jake Shoudy

August 19, 2022

CSCI 110 - Lecture 5

2 of 38

Today’s Agenda

  • Recap
  • Input/Output

3 of 38

Announcements

4 of 38

Reminder: Quiz0

Stop by my OH today (2-3pm) to get 100% on quiz #0!

5 of 38

Pre-class Surveys

Two surveys posted on Ed

Please take them 🙏 🙏 🙏

6 of 38

CS Emailing List

Posted in Ed.

If you are planning to be a Computer Science or Data Science minor or major fill out this form. Dr. Qian will be using it to create an email list that will be used for sending out information about important events, scholarships, internships, etc.

7 of 38

Fisk CS Club

8 of 38

Google TechExchange

What: Google program for HBCU students to learn CS things on Google campus (targeted at sophomores)

Google program leads will be on Fisk Campus to talk about it!

Timing: Aug 29th 2022, 5-7pm See more here

9 of 38

Feedback

Any feedback you have (positive or negative) about the class!

Totally anonymous!

https://forms.gle/26BY2r7LFQsPftMm6

10 of 38

Recap

11 of 38

Review: Conditionals

What are they?

if, elif, and else used to make decisions

Why are they important?

Allow for different behaviors based on conditions

12 of 38

Review: Conditionals

a = 25

if a > 20:

print(a)

a = a + 1

else:

a = a - 1

25

13 of 38

Review: Conditionals

x = 11

y = 5

if x + y <= 15:

print(x + y)

elif x - y <= 5:

print(x - y)

Nothing!

14 of 38

Review: Conditionals

first_str = 'abc'

second_str = 'def'

if first_str == second_str:

print(first_str * 3)

else:

print(second_str * 2)

if second_str != '':

print(first_str)

defdef

abc

15 of 38

Input/Output

16 of 38

I/O (Input / Output)

is everywhere

17 of 38

What is I/O?

18 of 38

<code>

User does something

19 of 38

Code takes user input,

does something

<code>

20 of 38

<code>

and responds to user's input by showing result of that something.

21 of 38

Let's look at an example.

22 of 38

Search

23 of 38

cats

24 of 38

cats

Cat Videos

Cat Images

Cats - Wikipedia

Cats the Broadway Show

Cats Definition

...

25 of 38

<code>

User types "cats",

Hits "Enter" key.

26 of 38

<code>

Code searches for items that have "cats".

27 of 38

<code>

And displays results to the user as a list.

28 of 38

Almost every app you use requires I/O.

Can you think of any?

29 of 38

What does this look like in code?

30 of 38

print('hello')

We know this.

31 of 38

name = ‘Hamzat’

print('hello ' + name)

And this.

32 of 38

name = ‘Hamzat’

print('hello ' + name)

What if we wanted to replace this with anything the user typed?

33 of 38

name = input('What is your name?')

print('hello ' + name)

Use this to prompt the user to type something.

34 of 38

name = input('What is your name?')

print('hello ' + name)

Once the user types their entry and hits the "enter" key...

It's stored in this variable as a STRING.

35 of 38

Communicating With User

input() lets user input text

print() outputs text to user

input() always gives a string; if want number, use int() or float() as appropriate

name = input("What is your name?")

print("Hi there, " + name)

age = int(input("How old are you?"))

print("Next year, you'll be " + (age + 1) + "years old.")

36 of 38

Let’s Code!

37 of 38

Review: I / O

What is it?

User providing input and receiving output

Why is this important?

Many programs and apps need user input, and based on input, program provides output

How (in Python)?

input(): get input from user

print(): show output to user

38 of 38

Questions?