



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This is introductory course for computer science. Its about basic concepts involving in computer programming, structure and working. Key points in this lecture handout are: String Operations, Input Function, Python Reuses, Built-In Type Conversion Functions, Float Function, Input Built-In Function
Typology: Study notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!




Today ...
Homework
Python reuses some math operations for strings
>>> first = "Hello" >>> second = "World!" >>> first + second ’HelloWorld!’ >>> first + " " + second ’Hello World!’
>>> "Ha" * 3 ’HaHaHa’ >>> 3 * "Ha" ’HaHaHa’
>>> "Ha" * "Ha" TypeError: can’t multiple sequence by non-int of type ’str’
>>> "Ha" + 3 TypeError: Can’t convert ’int’ object to str implicitly
The input command can be used to get user input
The input command always returns a string
>>> x = input("Please enter an x value: ") Please enter an x value: 5
>>> y = input("Please enter a y value: ") Please enter a y value: 6
>>> print(x + y) # what happens if >>> x + y 56 # displays ‘56’ (with quotes)
>>> type(x + y)
Q: How can we properly add x and y here?
>>> int(x) + int(y) 11
>>> type(int(x) + int(y))
>>> type(int(x + y))
>>> int(x + y) 56
Note that input is only for getting user information
Q: For example ... when is this useful?
def add(): x = input("Enter x: ") y = input("Enter y: ") return int(x) + int(y)