Skip to content

Instantly share code, notes, and snippets.

friends = ['Taylor', 'Alex', 'Pat', 'Eli']
for friend in friends:
print("Hi " + friend)
@AnisahTiaraPratiwi
AnisahTiaraPratiwi / HelloWorld_10Times.py
Created March 20, 2021 10:01
Printing "Hello, World" 10 times
for i in range(10):
print("Hello, World!")
@AnisahTiaraPratiwi
AnisahTiaraPratiwi / calculator.py
Created March 20, 2021 10:04
Replace the ___ placeholder and calculate the Golden ratio: \frac{1+\sqrt{5}}{2} 2 1+ 5 ​ ​ . Tip: to calculate the square root of a number xx, you can use x**(1/2).
ratio = ((1+(5**(1/2)))/2)
print(ratio)
@AnisahTiaraPratiwi
AnisahTiaraPratiwi / Calculator1.py
Created March 20, 2021 10:05
Most hard drives are divided into sectors of 512 bytes each. Our disk has a size of 16 GB. Fill in the blank to calculate how many sectors the disk has. Note: Your result should be in the format of just a number, not a sentence.
disk_size = 16*1024*1024*1024
sector_size = 512
sector_amount = (((16*1024*1024*1024)/512))
print(sector_amount)
@AnisahTiaraPratiwi
AnisahTiaraPratiwi / Expressions_and_Variables_1.py
Created March 20, 2021 10:08
In this scenario, two friends are eating dinner at a restaurant. The bill comes in the amount of 47.28 dollars. The friends decide to split the bill evenly between them, after adding 15% tip for the service. Calculate the tip, the total amount to pay, and each friend's share, then output a message saying "Each person needs to pay: " followed by …
bill = 47.28
tip = 0.15 * bill
total = bill + tip
share = total/2
print("Each person needs to pay: " + str (share))
@AnisahTiaraPratiwi
AnisahTiaraPratiwi / Expressions_and_Variables_2.py
Created March 20, 2021 10:09
This code is supposed to take two numbers, divide one by another so that the result is equal to 1, and display the result on the screen. Unfortunately, there is an error in the code. Find the error and fix it, so that the output is correct.
numerator = 10
denominator = 10
result = numerator / denominator
print(result)
@AnisahTiaraPratiwi
AnisahTiaraPratiwi / Expressions_and_Variables_3.py
Created March 20, 2021 10:10
Question 3 Combine the variables to display the sentence "How do you like Python so far?"
word1 = "How"
word2 = "do"
word3 = "you"
word4 = "like"
word5 = "Python"
word6 = "so"
word7 = "far?"
print("How " +"do ""you ""like ""Python ""so ""far?")
@AnisahTiaraPratiwi
AnisahTiaraPratiwi / Functions.py
Created March 20, 2021 10:13
Flesh out the body of the print_seconds function so that it prints the total amount of seconds given the hours, minutes, and seconds function parameters. Remember that there are 3600 seconds in an hour and 60 seconds in a minute.
def print_seconds(hours, minutes, seconds):
print(3600*hours+60*minutes+seconds)
print_seconds(1,2,3)
@AnisahTiaraPratiwi
AnisahTiaraPratiwi / ReturningValues.py
Created March 20, 2021 10:15
Use the get_seconds function to work out the amount of seconds in 2 hours and 30 minutes, then add this number to the amount of seconds in 45 minutes and 15 seconds. Then print the result.
def get_seconds(hours, minutes, seconds):
return 3600*hours + 60*minutes + seconds
amount_a = get_seconds(2,30,0)
amount_b = get_seconds(0,45,15)
result = amount_a + amount_b
print(result)
@AnisahTiaraPratiwi
AnisahTiaraPratiwi / CodeReuse.py
Created March 20, 2021 10:17
In this code, identify the repeated pattern and replace it with a function called month_days, that receives the name of the month and the number of days in that month as parameters. Adapt the rest of the code so that the result is the same. Confirm your results by making a function call with the correct parameters for both months listed.
# REPLACE THIS STARTER CODE WITH YOUR FUNCTION
def month_days(month,days):
print(month + " has " + str(days) + " days.")
month_days("June","30")
month_days("July","31")