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
capitals = {"London", "New York", "Kuala-Lumpur", "Den Haag", "Bern", "Peking"} | |
for city in capitals: | |
if city.find(' ') > 0: | |
print(f"This city's name is comprised of more than one word: {city}") | |
elif city.find('-') > 0: | |
print(f"This city's name is comprised of more than one word: {city}") | |
else: | |
print(f"This city's name is just one word: {city}") |
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
choice:bool = bool(input("Do you like anchovies (press ENTER for no)?")) | |
print(f"You chose: {choice}") |
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
students = {"a", "b", "c"} | |
if bool(students): | |
print (f"We have {len(students)} students in this class.") | |
else: | |
print ("We have no students in this class.") | |
stock = {} | |
if stock: | |
print (f"We have {len(stock)} items in stock.") | |
else: |
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
sentence:str = "The quick brown fox jumped over the lazy dog." | |
vowels:set = {"a","e","i","o","u",} | |
i:int = 0 | |
for letter in sentence: | |
if letter in vowels: | |
i+=1 | |
print(f"We found {i} vowels in: {sentence}") |
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
value:float = 0.0 | |
for n in range(10): | |
value+=0.1 | |
print(f"The current sum is: {value}") | |
assert value == 1.0, ("The value is not equal to 1.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
from decimal import * | |
setcontext(BasicContext) | |
i:Decimal = Decimal(0.0) | |
for value in range(10): | |
i += Decimal(0.1) | |
print(i) |
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
i:float = float(99.895321721389127643) | |
print(i) | |
print(round(i,2)) | |
print(f"{i:.2f}") |
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
citrusfruit:set = {"oranges", "lemons", "limes", "satsumas", "nectarines"} | |
treefruit:set = {"apples", "pears", "cherries", "plums", "peaches", "plums", "cherries", "oranges", "lemons", "limes"} | |
stonefruit:set = {"cherries", "plums", "peaches", "nectarines"} | |
#tree fruit with stones | |
print(treefruit.intersection(stonefruit)) | |
#tree fruit which are citrus | |
print(treefruit.intersection(citrusfruit)) |
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
geolocation:tuple = (25.001, 25.001) | |
students:set = {"Harry", "Tom", "Jane", "Sally"} | |
print(set(geolocation)) | |
print(tuple(students)) |
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 collections | |
geolocation = collections.namedtuple("geolocation", ["latitude", "longitude"]) | |
eiffel = geolocation(48.858093, 2.294694) | |
print(eiffel.latitude) | |
print(eiffel.longitude) |