sun = 'down'
if sun == 'down': print('Good Night!')
print('I am here')
sun = 'up'
if sun == 'down': print('Good Night!')
print('I am here')
total = 100
sales_tax_rate = 0.065
taxable = True
if taxable:
print(f"Subtotal : ${total:.2f}")
sales_tax = total * sales_tax_rate
print(f"Sales Tax: ${sales_tax:.2f}")
total = total + sales_tax
print(f"Total : ${total:.2f}")
import datetime as dt
# Get the current date and time
now = dt.datetime.now()
# Make a decision based on hour
if now.hour < 12 :
print('Good Morning')
else:
print('Good afternoon')
print('I hope you are doing well!')
light_color = "green"
if light_color == "green":
print("Go")
elif light_color == "red":
print("Stop")
print("This code executes no matter what")
age = 31
if age < 21:
# If under 21, no alcohol
beverage = "milk"
elif age >= 21 and age < 80:
# Ages 21 - 79, suggest beer
beverage = "beer"
else:
# If 80 or older, prune juice might be a good choice.
beverage = "prune juice"
print("Have a " + beverage)
for x in range(7):
print(x)
print("All done")
for x in "Eslam":
print(x)
print("Done")
for x in ["The", "rain", "in", "Spain"]:
print(x)
print("Done")
answers = ["A", "C", "", "D"]
for answer in answers:
if answer == "":
print("Incomplete")
break
print(answer)
print("Loop is done")
answers = ["A", "C", "", "D"]
for answer in answers:
if answer == "":
print("Incomplete")
continue
print(answer)
print("Loop is done")
counter= 65
while counter < 91:
print(str(counter) + "=" + chr(counter))
counter +=1
print("all done")
import random
print("Numbers that aren't evenly divisible by 5")
counter = 0
while counter < 10:
# Get a random number
number = random.randint(1,999)
if int(number / 5) == number / 5:
# If it's evenly divisible by 5, bail out.
continue
# Otherwise, print it and keep going for a while.
print(number)
# Increment the loop counter.
counter += 1
print("Loop is done")
import random
print("Numbers that aren't evenly divisible by 5")
counter = 0
while counter < 10:
# Get a random number
number = random.randint(1,999)
if int(number / 5) == number / 5:
# If it's evenly divisible by 5, bail out.
break
# Otherwise, print it and keep going for a while.
print(number)
# Increment the loop counter.
counter += 1
print("Loop is done")