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 sing(num_bottles): | |
#TODO: Add your code to achieve the desired output and pass the challenge. | |
#NOTE: The f String method of String Interpolation does not work. | |
lyrics = [] | |
for num in range(num_bottles, 0, -1): | |
lyrics.append('{num} bottles of beer on the wall, {num} bottles of beer.'.format(num = num)) | |
lyrics.append('Take one down and pass it around, {num} bottles of beer on the wall.'.format(num = num - 1)) | |
lyrics.append('') | |
return lyrics |
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
# TODO: Write a function called concatenate_lists that has two parameters and returns the combined list. | |
def concatenate_lists(first_list, second_list): | |
result = first_list + second_list | |
return result |
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
# TODO 1: Add two parameters (length_ft and width_ft) | |
def calc_square_meters_from_feet(length_ft, width_ft): | |
# TODO 2: Modify the code below: | |
metric_length = length_ft * 0.3048 | |
metric_width = width_ft * 0.3048 | |
metric_area = metric_length * metric_width | |
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
tracker = 0 | |
def moveForwards(): | |
global tracker | |
tracker += 1 | |
print('moved forward by one step.') | |
def turnRight(): | |
global tracker | |
tracker -= 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 top_three(scores): | |
scores = scores | |
top_scores = [] | |
# Solution | |
scores.sort() | |
list_size = len(scores) | |
top_scores = [scores[list_size-1], scores[list_size-2], scores[list_size-3]] | |
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 test(A, B): | |
a = A | |
b = B | |
# TODO: Below this comment write your code. | |
c = a | |
a = b | |
b = c |
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
// Define a struct | |
struct User { | |
var name: String | |
var email: String? | |
var followers: Int | |
var isActive: Bool | |
func logStatus() { | |
if (isActive) { | |
print("\(name) is working hard") |
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
//Write your code here. | |
// Solution | |
let secondsInAnHour = 3600 | |
// alternatively: | |
// let secondsInAnHour: Int = 3600 | |
// Note, constants can only be set once and cannot be assigned a new value. | |
// The below does not work, because it is a constant and thus cannot be changed. |
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
func isOdd(n: Int) -> Bool { | |
if n % 2 != 0 { | |
return true | |
} else { | |
return false | |
} | |
// Alternatively: | |
// return n % 2 != 0 | |
} |
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
//Don't change this | |
var studentsAndScores = ["Amy": Int(readLine()!)!, "James": Int(readLine()!)!, "Helen": Int(readLine()!)!] | |
func highestScore(scores: [String: Int]) { | |
//Write your code here. | |
let a = studentsAndScores["Amy"]! | |
let b = studentsAndScores["James"]! | |
let c = studentsAndScores["Helen"]! |