Download presentation
Presentation is loading. Please wait.
1
Python – Input & Output
2
Output (to the terminal)
print(“Hello, world!”) # What if we want to output multiple things? print(“hello”, “world!”, 1, 2, 3) # separate with commas
3
Input (via the terminal)
We will use the input() function: input(“prompt”) line = input(“Please enter something:”) print(line) # line is a string
4
Input with numbers (incorrectly)
x = input(“Num 1:”) y = input(“Num 2:”) print(x+y) # What do we see?
5
Input with numbers (correctly)
x = input(“Num 1:”) x = int(x) #convert x to an int y = int(input(“Num 2:”)) #we can also put it all in one line print(x+y) # What do we see?
6
Input with floats x = input(“Num 1:”)
x = float(x) #convert x to an float y = float(input(“Num 2:”)) #we can also put it all in one line print(x+y) # What do we see?
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.