Core Python Part 1
Core Python Part 1
https://colab.research.google.com/drive/14subOArsgsekUJVEcCTaYSUz0kq0s4Ix Page 1 of 10
Corey_Python_1.ipynb - Colab 10/05/24, 6:35 PM
import typing
a:int = 1
b:str = "Hello World"
c: float = 2.0
d:typing.List[int] = [1, 2, 3]
e:typing.Tuple[int, int, int] = (4, 5, 6)
f: typing.Dict[str, int] = {"k1": 1, "k2": 2}
g: typing.Set[int] = {7, 8, 9}
print(a)
print(b)
print(c)
print(d)
print(e)
print(f)
print(g)
1
Hello World
2.0
[1, 2, 3]
(4, 5, 6)
{'k1': 1, 'k2': 2}
{8, 9, 7}
https://colab.research.google.com/drive/14subOArsgsekUJVEcCTaYSUz0kq0s4Ix Page 2 of 10
Corey_Python_1.ipynb - Colab 10/05/24, 6:35 PM
greeting("Kay", "HR")
greeting("Cameron", "Finance")
a_list = [4, 6, 8, 1, 2, 7, 3, 5]
s_list = sorted(a_list)
print(a_list)
print(s_list)
print(max(a_list))
print(min(a_list))
[4, 6, 8, 1, 2, 7, 3, 5]
[1, 2, 3, 4, 5, 6, 7, 8]
8
1
True
x = 0
while(x < 5):
print("The value of x is", str(x))
x = x + 1
print("x = " + str(x))
The value of x is 0
The value of x is 1
The value of x is 2
The value of x is 3
The value of x is 4
x = 5
https://colab.research.google.com/drive/14subOArsgsekUJVEcCTaYSUz0kq0s4Ix Page 3 of 10
Corey_Python_1.ipynb - Colab 10/05/24, 6:35 PM
greeting = 'Hello'
index = 0
while index < len(greeting):
print(greeting[index:index+2])
index += 1
He
el
ll
lo
o
def format_phone(phonenum):
area_code = "(" + phonenum[:3] + ")"
exchange = phonenum[3:6]
line = phonenum[-4:]
return area_code + " " + exchange + "-" + line
(202) 555-1212
def even_numbers(n):
count = 0
current_number = 0
while current_number <= n: # Complete the while loop condition
if current_number % 2 == 0:
count += 1 # Increment the appropriate variable
current_number += 1 # Increment the appropriate variable
return count
13
73
501
1
https://colab.research.google.com/drive/14subOArsgsekUJVEcCTaYSUz0kq0s4Ix Page 4 of 10
Corey_Python_1.ipynb - Colab 10/05/24, 6:35 PM
def even_numbers(n):
count = 0
current_number = 0
while current_number <= n: # Complete the while loop condition
if current_number % 2 == 0:
count += 1 # Increment the appropriate variable
current_number += 1 # Increment the appropriate variable
return count
13
73
501
1
https://colab.research.google.com/drive/14subOArsgsekUJVEcCTaYSUz0kq0s4Ix Page 5 of 10
Corey_Python_1.ipynb - Colab 10/05/24, 6:35 PM
0
2
4
6
8
'abc@bing.com'
'test'
https://colab.research.google.com/drive/14subOArsgsekUJVEcCTaYSUz0kq0s4Ix Page 6 of 10
Corey_Python_1.ipynb - Colab 10/05/24, 6:35 PM
['Hello', ' Nice Meeting you', ' How are you doing today?']
name = "Sam"
number = 9876543210
salary = 50000
print("Hi {}, Thanks for sharing your number {}. Your salary is ${:>10.2f}".format(
Hi Sam, Thanks for sharing your number 9876543210. Your salary is $ 50000.00
name = "Sam"
number = 9876543210
salary = 50000
print(f"Hi {name}, Thanks for sharing your number {number}. Your salary is ${salary
Hi Sam, Thanks for sharing your number 9876543210. Your salary is $ 50000.00
https://colab.research.google.com/drive/14subOArsgsekUJVEcCTaYSUz0kq0s4Ix Page 7 of 10
Corey_Python_1.ipynb - Colab 10/05/24, 6:35 PM
def is_palindrome(input_string):
# Two variables are initialized as string date types using empty
# quotes: "reverse_string" to hold the "input_string" in reverse
# order and "new_string" to hold the "input_string" minus the
# spaces between words, if any are found.
new_string = ""
reverse_string = ""
if new_string.lower() == reverse_string.lower():
NeverOddorEven
nevEroddOreveN
True
https://colab.research.google.com/drive/14subOArsgsekUJVEcCTaYSUz0kq0s4Ix Page 8 of 10
Corey_Python_1.ipynb - Colab 10/05/24, 6:35 PM
words = []
word = "hello"
a = len(word)
word
def count_letters(text):
result = {}
for letter in text:
if letter not in result:
result[letter] = 0
result[letter] += 1
return result
count_letters("aaaaa")
{'a': 5}
https://colab.research.google.com/drive/14subOArsgsekUJVEcCTaYSUz0kq0s4Ix Page 9 of 10
Corey_Python_1.ipynb - Colab 10/05/24, 6:35 PM
https://colab.research.google.com/drive/14subOArsgsekUJVEcCTaYSUz0kq0s4Ix Page 10 of 10