def main(): print("O hai! How much change is owed?") while True: change = cs50.get_float() if change >= 0: break print("How much change is owed?") result = check_coins(change) print(result) return 0
def main(): # get positive float from user while True: print("How much change is owed ($)?: ") user_owed = cs50.get_float() if (user_owed >= 0): break # clean input and determine min number of coins cents = int(round(100 * user_owed)) print(coin_count(cents))
def countField(): typ = 0 while typ != 'circle' and typ != 'rectangle' and typ != 'triangle' and typ != 'rhombus': typ = input( "Please give the type of figure (circle/rectangle/triangle/rhombus) " ) if typ == 'circle': x = 0 while x <= 0: x = get_float("Give radius ") if x <= 0: print("Radius must be > 0 ") if x > 0: Field_circle = pi * x**2 print("The field is ", Field_circle) if typ == 'rectangle': x = 0 y = 0 while x <= 0 or y <= 0: x = get_float("Give 1st side ") y = get_float("Give 2nd side ") if x <= 0: print("1st side must be > 0") if y <= 0: print("2nd side must be > 0") if x > 0 and y > 0: Field_rectangle = x * y print("The field is ", Field_rectangle) if typ == 'triangle': x = 0 y = 0 while x <= 0 or y <= 0: x = get_float("Give the base ") y = get_float("Give the height ") if x <= 0: print("Base must be > 0") if y <= 0: print("Height must be > 0") if x > 0 and y > 0: Field_triangle = x * y * 0.5 print("The field is ", Field_triangle) if typ == 'rhombus': x = 0 y = 0 while x <= 0 or y <= 0: x = get_float("Give the 1st diagonal ") y = get_float("Give the 2nd diagonal ") if x <= 0: print("1st diagonal must be > 0") if y <= 0: print("2nd diagonal must be > 0") if x > 0 and y > 0: Field_rhombus = x * y * 0.5 print("The field is ", Field_rhombus) if typ != 'circle' and typ != 'rectangle' and typ != 'triangle' and typ != 'rhombus': print("Please give another type of figure")
def main(): while True: #get number from user changeOwed = get_float("Change owed: ") #check if valid if changeOwed > 0: break totalCents = changeOwed * 100 finalResult = calculateCoinCount(totalCents) print("The total number of coins is: ", finalResult)
def main(): # first ask cash = get_float("Change Owed:") # while user does not obey master while cash < 0: cash = get_float("Change Owed:") # Initialize Count count = 0 # multiple by 100 cash = cash * 100 # greedy algorithm while cash > 0: # Take a quarter if cash >= 25: cash -= 25 count += 1 # Take a dime elif (cash < 25 and cash >= 10): cash -= 10 count += 1 # Take a nickel elif (cash < 10 and cash >= 5): cash -= 5 count += 1 # Take a penny else: cash -= 1 count += 1 # Print answer print(count)
def main(): # Setting the condition that the user must meet if not it will keep asking until right input is given while True: ## Getting input from the user dollar = get_float("Change owed: ") # The input should be a non-negative integer if dollar >= 0: break # Changing the dollar input into cents change = int(dollar * 100) # Calling the function to calculate the amount calc(change)
def __init__(self): self.change = -1 self.penny = 1 self.nickel = 5 self.dime = 10 self.quarter = 25 self.total_coins = 0 # prompt for change while self.change < 0: self.change = get_float("Change owed: ") self.cents_owed = round(self.change * 100)
def main(): p = 0 n = 0 q = 0 d = 0 print("O hai! How much change is owed? ", end="") change = cs50.get_float() while change < 0.00: print("Retry, how much change", end="") change = cs50.get_float() if change > 0.00: break if change >= 0.00: x = change * 1000 while x >= 250: x = x - 250 q += 1 while x >= 100: x = x - 100 d += 1 while x >= 50: x = x - 50 n += 1 while x >= 10: x = x - 10 p += 1 total = p + n + d + q print("{}".format(total))
def main(): while True: cash = get_float("Change owed: ") # make sure its more than 0 if cash >= 0: # get the change we have to give back change = get_change(cash) # display it on the screen print(f"{change}") # break out of the loop break
def main(): while True: dollars_owed = get_float("Change owed: ") cents_owed = floor(dollars_owed * 100) if cents_owed > 0: break quarters = cents_owed // 25 dimes = (cents_owed % 25) // 10 nickels = ((cents_owed % 25) % 10) // 5 pennies = ((cents_owed % 25) % 10) % 5 total = quarters + dimes + nickels + pennies print(total)
def main(): count = 0 while count == 0: h = get_float("Enter change amount in dollars: ") if h >= 0: h = round(h * 100) q = h // 25 d = (h - 25 * q) // 10 n = round((h - 25 * q - 10 * d), 2) // 5 p = round((h - 25 * q - 10 * d - 5 * n), 2) // 1 count = q + d + n + p print(count) else: print('Your number should be positive')
def main(): numb = cs50.get_float() numb = int(numb) if isnum(numb): if isamex(numb): print('AMEX') elif ismcrd(numb): print('MASTERCARD') elif isvisa(numb): print('VISA') else: print('INVALID') else: print("INVALID")
def main(): while True: # while cents_owed < 0 or string dollars_owed = get_float('Change owed: ') cents_owed = floor(dollars_owed * 100) if cents_owed > 0: break quarters = cents_owed // 25 # cents divide by 25 dimes = (cents_owed % 25) // 10 # remaining cents divide by 10 nickles = ((cents_owed % 25) % 10) // 5 # remaining cents divide by 5 pennies = (((cents_owed % 25) % 10) % 5) # remaining cents print(f"{quarters + dimes + nickles + pennies}") # printing result
def main(): print("Number : ", end="") i = cs50.get_float() s = i // 100000000000000 if s == 3: print("AMEX") elif s == 51 or s == 52 or s == 53 or s == 54 or s == 55: print("MASTERCARD") elif s > 9 and s < 99 and s != 51 and s != 52 and s != 53 and s != 54 and s != 55: print("VISA") else: print("INVALID")
def main(): while True: money_owed = get_float("Change owed: ") cents_owed = floor(money_owed * 100) if cents_owed > 0: break quarters = cents_owed // 25 dimes = (cents_owed % 25) // 10 nickels = ((cents_owed % 25) % 10) // 5 pennies = ((cents_owed % 25) % 10) % 5 print(f"{quarters + dimes + nickels + pennies}")
def main(): while True: change = get_float("Change owed: ") cents = floor(change * 100) if change > 0: break quarters = cents // 25 dimes = (cents % 25) // 10 nickels = ((cents % 25) % 10) // 5 pennies = ((cents % 25) % 10) % 5 print(f"{quarters + dimes + nickels + pennies}")
def main(): while True: amount = get_float("Change owed: ") if (amount > 0): break counter = 0 for x in [0.25, 0.10, 0.05, 0.01]: while amount >= x: amount = round(amount - x, 2) counter += 1 print(f"The minimum amount of coins is {counter}")
def main(): global CHANGE # Makes sure the value of change is positive while (CHANGE < 0): CHANGE = get_float("Change owed: ") # Rounds and multiplies CHANGE by 100 to make sure the variable is accurate CHANGE *= 100 round(CHANGE) # Adds the value of the function coins with the value of a quarter, dime, nickel, and penny coinCount = coins(25) + coins(10) + coins(5) + coins(1) print(f"{coinCount}")
def GetPositiveFloatWithMessage(message): while True: print(message) number = cs50.get_float() if number >= 0: break print("Please type the positive number or zero!") return number
def main(): # Get input change = get_float("Change owed: ") # Make sure input is positive while (change <= 0): change = get_float("Change owed: ") # Set up coin list coinlist = [.25, .10, .05, .01] # Iterate through coin list, doing math for i in coinlist: # Slightly different for first item if i == .25: counter = change // i remainder = round(change % i, 2) # For the subsequent passes else: counter += remainder // i remainder = round(remainder % i, 2) # Print answer without the float print(int(counter))
def main(): # Get input from the user while True: n = get_float("Change owned: ") if n >= 0: break # Round the float input to an integer cents = round(n * 100) # Initialize quarters, dimes, nickels, pennies and coins q = 0 d = 0 n = 0 p = 0 coins = 0 # Check for quarters while (cents >= 25): q += 1 coins += 1 cents = cents - 25 print(f"Quarters: {q}") print(f"Cents after quarters: {cents}") # Check for dimes while (cents >= 10): d += 1 coins += 1 cents = cents - 10 print(f"Dimes: {d}") print(f"Cents after dimes: {cents}") # Check for nickels while (cents >= 5): n += 1 coins += 1 cents = cents - 5 print(f"Nickels: {n}") print(f"Cents after nickels: {cents}") # Check for pennies while (cents >= 1): p += 1 coins += 1 cents = cents - 1 print(f"Pennies: {p}") print(f"Cents after pennies: {cents}") print(f"Total coins: {coins}")
def main(): while True: change = cs50.get_float("Change owed: ") if change > 0: break change = round(change * 100) q = change // 25 # quarters d = (change % 25) // 10 # dimes n = ((change % 25) % 10) // 5 # nickles p = ((change % 25) % 10) % 5 # pennies print(f"{q + d + n + p}")
def main(): while True: dollar = get_float("Change owed: ") cents = round(dollar * 100) if dollar > 0: break quarters = cents // 25 dimes = (cents % 25) // 10 nickels = ((cents % 25) % 10) // 5 pennies = ((cents % 25) % 10) % 5 counter = quarters + dimes + nickels + pennies print(counter)
def main(): summ = 0 coin = [25, 10, 5, 1] while True: print( "How much change is owed? Note: 6.22 represents 6 dollars and 22 cents.: ", end="") amount = cs50.get_float() break cents = round(amount * 100.0) for i in range(4): summ = summ + cents / coin[i] cents = cents % coin[i] summ = int(summ) print("{}".format(summ))
def main(): while True: # Get input from the user dollars_owed = get_float("How much change is owed?: ") cents_owed = round(dollars_owed * 100) if cents_owed > 0: break q = cents_owed // 25 d = (cents_owed % 25) // 10 n = ((cents_owed % 25) % 10) // 5 p = ((cents_owed % 25) % 10) % 5 print(f"{q + d + n + p}")
def main(): # Make sure input is valid while True: dollars = get_float("Change owed: ") if dollars >= 0: break # Better to operate with integers than floats cents = round(dollars * 100) # Call check on cents number of cents numberOfCoins = check(cents, [1, 5, 10, 25]) # Print result print(numberOfCoins)
def main(): while True: print("How much change is needed? ", end="") change = cs50.get_float() if change < 0: print("A negative amount of change cannot be given! Please enter a positive value") if change >= 0: break cents = 100 * change CalculateChange(cents)
def main(): # ask the user for the amount owed while True: dollars_owed = get_float("Change owed: ") cents_owed = floor(dollars_owed * 100) if cents_owed > 0: break # breakdown of all the coins, see cash.c quarters = cents_owed // 25 dimes = (cents_owed % 25) // 10 nickels = ((cents_owed % 25) % 10) // 5 pennies = ((cents_owed % 25) % 10) % 5 # sum of all the coins we owed print(f"{quarters + dimes + nickels + pennies}")
def main(): while True: change = get_float("Change owed: ") if change > 0: break change = round(change * 100) coins_needed = 0 denominations = [25, 10, 5, 1] for i in denominations: if i <= change: coins_needed += change // i change -= (change // i) * i print(coins_needed)
def main(): while True: change=cs50.get_float("Change owed: ") if change>=0: break coins=0 change*=100 change=round(change) coins+=change//25 change%=25 coins+=change//10 change%=10 coins+=change//5 change%=5 coins+=change print(coins)
def main(): # prompts user for change owed while True: dollars_owed = get_float("Change owed: ") cents_owed = floor(dollars_owed * 100) if cents_owed > 0: break # calculates no of coins greedily quarters = cents_owed // 25 dimes = (cents_owed % 25) // 10 nickels = ((cents_owed % 25) % 10) // 5 pennies = ((cents_owed % 25) % 10) % 5 # prints total no of coins print(f"{quarters + dimes + nickels + pennies}")
def main(): while True: print("O hai! How much change is owed?") amount = cs50.get_float() if amount >= 0: break number_of_coins = 0 cents = int(round(amount * 100)) number_of_coins += cents // 25 cents %= 25 number_of_coins += cents // 10 cents %= 10 number_of_coins += cents // 5 cents %= 5 number_of_coins += cents print("{}".format(number_of_coins))
import cs50 f = cs50.get_float() c = 5 / 9 * (f - 32) print("{:.1f}".format(c))
import cs50 # prompt user for x print("x is ", end="") x = cs50.get_float() # prompt user for y print("y is ", end="") y = cs50.get_float() # perform division for user print("{} divided by {} is {}".format(x, y, x / y))