Skip to content

Instantly share code, notes, and snippets.

@andrija-zikovic
Created May 26, 2023 11:33
Show Gist options
  • Save andrija-zikovic/bd9b74c25632f1239f4275b2e6d320e1 to your computer and use it in GitHub Desktop.
Save andrija-zikovic/bd9b74c25632f1239f4275b2e6d320e1 to your computer and use it in GitHub Desktop.
CS50 Sentimental staff
from cs50 import get_float
import decimal
def main():
## Ask how many dollars the customer is owed
while True:
dollars = get_float("Change owned: ")
if dollars > 0:
break
## Calculate the number of quarters to give the customer
quarters = calculate_quarters(dollars)
dollars = dollars - quarters * 0.25
dollars = round(dollars, 2)
## Calculate the number of dimes to give the customer
dimes = calculate_dimes(dollars)
dollars = dollars - dimes * 0.10
dollars = round(dollars, 2)
## Calculate the number of nickles to givw the customer
nickles = calculate_nickels(dollars)
dollars = dollars - nickles * 0.05
dollars = round(dollars, 2)
## Calculate the number of pennies to give the customer
pennies = calculate_pennies(dollars)
dollars = dollars - pennies * 0.01
dollars = round(dollars, 2)
## Sum coins
coins = quarters + dimes + nickles + pennies
## Print total number of coins to give the customer
print(int(coins))
def calculate_quarters(dollars):
quarters = 0.00
while (dollars >= 0.25):
dollars = dollars - 0.25
quarters += 1
return quarters
def calculate_dimes(dollars):
dimes = 0.00
while (dollars >= 0.10):
dollars = dollars - 0.10
dimes += 1
return dimes
def calculate_nickels(dollars):
nickels = 0.00
while (dollars >= 0.05):
dollars = dollars - 0.05
nickels += 1
return nickels
def calculate_pennies(dollars):
pennies = 0.00
while (dollars >= 0.01):
dollars = dollars - 0.01
pennies += 1
return pennies
main()
def main():
num = input("Number: ")
if (len(num) / 15) == 1:
if num.startswith('34') or num.startswith('37'):
print("AMEX")
else:
print("INVALID")
elif (len(num) / 16) == 1:
for i in range(51, 56):
if num.startswith(str(i)):
print("MASTERCARD")
if num.startswith('4'):
if visa(num) == True:
print("VISA")
else:
print("INVALID")
else:
print("INVALID")
elif (len(num) / 13) == 1:
if num.startswith('4'):
if visa(num) == True:
print("VISA")
else:
print("INVALID")
else:
print("INVALID")
else:
print("INVALID")
def visa(num):
x = 0
y = 0
z = 0
number = ''
for i in range(len(num)-2, -1, -2):
x = int(num[i]) * 2
number += str(x)
for i in range(len(number)):
z += int(number[i])
for i in range(len(num)-1, -1, -2):
y += int(num[i])
if (z + y) % 10 == 0 :
return True
else:
return False
main()
# TODO
from cs50 import get_int
## promp user for valide input
while True:
try:
num = get_int("Height: ")
if num < 1 or num > 8:
raise ValueError
break
except ValueError:
print("Invalid input")
## print each char with its oun loop
for r in range(num):
for s in range(num - r - 1, 0, -1):
print(" ", end="")
for h in range(r + 1):
print("#", end="")
print(" ", end="")
for rh in range(r+1):
print("#", end="")
print("\n", end="")
def main():
text = input("Text: ")
text = text.lower()
leters_count = 0
words_count = 0
sentences_count = 0
for char in "abcdefghijklmnopqrstuvwxyz":
leters = text.count(char)
leters_count += leters
words_count = text.count(" ") + 1
for char in ".!?":
sentence = text.count(char)
sentences_count += sentence
L = leters_count / words_count * 100
S = sentences_count / words_count * 100
subindex = 0.0588 * L - 0.296 * S - 15.8
index = round(subindex)
if (index < 1):
print("Before Grade 1")
elif (index > 16):
print("Grade 16+")
else:
print(f"Grade {index}")
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment