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
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
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
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
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
#Let's define a string to begin with. | |
sentence = "The quick brown fox jumped over the lazy dog." | |
#let's show the string with all characters in lower case | |
print(f"Lower case representation:\n{ sentence.lower() }") | |
#let's show the string with all characters in title case | |
print(f"Title case representation:\n{ sentence.title() }") |
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 = {"[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]"} | |
for student in students: | |
print (student) |
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
print (f"1 and 1: {bool(1 and 1)}") | |
print (f"0 and 0: {bool(0 and 0)}") | |
print (f"1 and 0: {bool(1 and 0)}") | |
print (f"not 0: {bool(not 0)}") | |
print (f"not 1: {bool(not 1)}") | |
print (f"1 or 1: {bool(1 or 1)}") | |
print (f"0 or 0: {bool(0 or 0)}") | |
print (f"1 or 0: {bool(1 or 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
age = input("Please tell me your age: ") | |
age = int(age) | |
if age < 21: | |
print ("You may not hire a vehichle.") | |
elif age <25: | |
print ("We will add a 'young driver fee' to your rental bill.") | |
elif age < 45: | |
print ("Do you require a child seat for a small daily fee?") | |
elif age > 55: |
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
age = input("Please tell me your age: ") | |
age = int(age) | |
if age < 21: | |
print ("No alcohol can be served to you.") | |
else: | |
print ("Which drink may I prepare for you?") |