Docsity

python lab assignments - Python Basics, Lab Reports of Artificial Intelligence

Toggle sidebar
bg1
Lab. 1 practice
Python Basics
Overview
Understanding data types
How to use variables
Seeing what you can do with strings
How to manipulate a string
Coding a program that prints receipts
Writing Comments
we can write comments using the hash (#) symbol
# this is a comment
print("Hello") # this is also a comment
What Are Data Types?
Data types are how we define values, likes words or numbers.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download python lab assignments - Python Basics and more Lab Reports Artificial Intelligence in PDF only on Docsity!

Lab. 1 practice

Python Basics

Overview  Understanding data types  How to use variables  Seeing what you can do with strings  How to manipulate a string  Coding a program that prints receipts Writing Comments we can write comments using the hash (#) symbol

this is a comment

print("Hello") # this is also a comment What Are Data Types? Data types are how we define values, likes words or numbers.

The Print Statement Integers Floats

Yes or No

Booleans

Integer and Float Variables Boolean Variables String Variables Using Multiple Variables Using Operators on Numerical Variables

Overwriting Previously Created Variables Whitespace Whitespace just means characters which are used for spacing and have an “ empty ” representation. name = 'John Smith' Exercise String Concatenation

String Index String Slicing Slicing is essentially when you only want a piece of the variable, such that if I only wanted “He” from the word “Hello”, we would write the following: >>> variable_name[ start : stop : step ] .title( ) The title method capitalizes all first letters in each word of a string .replace( )

.find( )

The output will produce the 5. Find returns the starting index position of the match

.strip( ) In cases where you want to get rid of a certain character on the left and right side of a string, you would use the strip method. By default, it will remove spaces .split( )

Displaying the Company Info Create a divider: Displaying the Product Info

Displaying the Total section border: Displaying the Ending Message Displaying the Bottom Border

Converting User Input If Statements Checking User Input Logical Operator “and”

Logical Operator “or” The “or” logical operator is used to check for one or both conditions to be true Logical Operator “not” Practice Question Q Q