This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mysql.connector | |
try: | |
database_connection = mysql.connector.connect( | |
host = '<host_name>', | |
port = <port_number>, | |
db = '<database_name>', | |
user = '<database_user>', | |
passwd = '<database_password>', | |
charset = '<database_character_set>', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def max(ints: List[Int]): Int = ints match{ | |
case Nil => 0 | |
case head :: tail => if (head > max(tail)) head else max(tail) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def productOfList(ints: List[Int]): Int = { | |
def loop(ints: List[Int]): Int = ints match{ | |
case Nil => 1 | |
case head :: tail => head * loop(tail) | |
} | |
if (ints.isEmpty) 0 | |
else loop(ints) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sumOfList(ints: List[Int]): Int = ints match{ | |
case Nil => 0 | |
case head :: tail => head + sumOfList(tail) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fibonacciNumberOf(n: Int): Int = n match{ | |
case 0 => 1 | |
case 1 => 1 | |
case _ => fibonacciNumberOf(n - 2) + fibonacciNumberOf(n - 1) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def factorial(n: Int): Int = { | |
if (n == 0) 1 | |
else factorial(n - 1) * n | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sumOfLessthan(n: Int): Int = { | |
def loop(n: Int): Int = { | |
if (n == 1) 1 | |
else sumOfLessthan(n - 1) + n | |
} | |
if (n < 1) 0 | |
else loop(n) | |
} |