Jun 7, 2024
print("Hello, World!")
print("/\")
print("/ \")
print("/____\")
character_name = "John"
character_age = 35
print(character_name, character_age)
is_male = True
character_age = 50.5
character_name = "Mike"
phrase = "Draft Academy"
print(phrase.upper()) # Uppercase
print(phrase.isupper()) # Boolean check
.upper()
, .lower()
, .isupper()
, .islower()
.index()
print(phrase[0])
print(phrase.index("A"))
print(phrase + " is cool")
print(3 + 4)
print(3 * 4)
abs()
, pow()
, max()
, min()
, round()
, math.sqrt()
import math
print(abs(-5))
print(math.sqrt(36))
name = input("Enter your name: ")
print("Hello " + name + "!")
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
result = num1 + num2
print(result)
is_male = True
if is_male:
print("You are a male")
else:
print("You are not a male")
==
, !=
, <
, >
, <=
, >=
if num1 == num2:
print("Equal")
monthConversions = {
"Jan": "January",
"Feb": "February"
}
print(monthConversions["Jan"])
.get()
and handling missing keys
print(monthConversions.get("Luv", "Not a valid key"))
i = 1
while i <= 10:
print(i)
i += 1
friends = ["Jim", "Karen", "Kevin"]
for friend in friends:
print(friend)
def raise_to_power(base_num, pow_num):
result = 1
for index in range(pow_num):
result *= base_num
return result
print(raise_to_power(2, 3)) # Output: 8
number_grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
print(number_grid[0][0]) # Output: 1
for row in number_grid:
for col in row:
print(col)
def say_hi(name):
print("Hello " + name)
say_hi("Mike")
def cube(num):
return num * num * num
print(cube(3))
def translate(phrase):
translation = ""
for letter in phrase:
if letter in "AEIOUaeiou":
translation += "g"
else:
translation += letter
return translation
print(translate("Hello")) # Output: Hgllg
employee_file = open("employees.txt", "r")
print(employee_file.read())
employee_file.close()
employee_file = open("employees.txt", "a")
employee_file.write("Toby - Human Resources")
employee_file.close()
import math
print(math.sqrt(36))
pip install [module-name]
class Student:
def __init__(self, name, major, gpa):
self.name = name
self.major = major
self.gpa = gpa
student1 = Student("Jim", "Business", 3.1)
print(student1.name)
class Student:
def on_honor_roll(self):
if self.gpa >= 3.5:
return True
return False
student1 = Student("Jim", "Business", 3.1)
print(student1.on_honor_roll()) # Output: False
class Chef:
def make_chicken(self):
print("The chef makes a chicken")
class ChineseChef(Chef):
def make_special_dish(self):
print("The chef makes orange chicken")
myChef = Chef()
myChef.make_chicken()
myChineseChef = ChineseChef()
myChineseChef.make_special_dish()
python3
>>> print("Hello, World!")