Input and Output (I/O)
Jake Shoudy
August 19, 2022
CSCI 110 - Lecture 5
Today’s Agenda
|
|
| |
| |
| |
| |
Announcements
Reminder: Quiz0
Stop by my OH today (2-3pm) to get 100% on quiz #0!
Pre-class Surveys
Two surveys posted on Ed
Please take them 🙏 🙏 🙏
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.
Fisk CS Club
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
Feedback
Any feedback you have (positive or negative) about the class!
Totally anonymous!
Recap
Review: Conditionals
What are they?
if, elif, and else used to make decisions
Why are they important?
Allow for different behaviors based on conditions
Review: Conditionals
a = 25
if a > 20:
print(a)
a = a + 1
else:
a = a - 1
25
Review: Conditionals
x = 11
y = 5
if x + y <= 15:
print(x + y)
elif x - y <= 5:
print(x - y)
Nothing!
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
Input/Output
I/O (Input / Output)
is everywhere
What is I/O?
<code>
User does something
Code takes user input,
does something
<code>
<code>
and responds to user's input by showing result of that something.
Let's look at an example.
Search
cats
cats
Cat Videos
Cat Images
Cats - Wikipedia
Cats the Broadway Show
Cats Definition
...
<code>
User types "cats",
Hits "Enter" key.
<code>
Code searches for items that have "cats".
<code>
And displays results to the user as a list.
Almost every app you use requires I/O.
Can you think of any?
What does this look like in code?
print('hello')
We know this.
name = ‘Hamzat’
print('hello ' + name)
And this.
name = ‘Hamzat’
print('hello ' + name)
What if we wanted to replace this with anything the user typed?
name = input('What is your name?')
print('hello ' + name)
Use this to prompt the user to type something.
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.
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.")
Let’s Code!
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
Questions?