Ejemplo n.º 1
0
def main():

    # Get height from user between 0 and 23
    height = cs50.get_int("Height: ")

    while not 0 < height < 23:
        height = cs50.get_int("Height: ")

    for i in range(height):
        spaces = " " * (height - i - 1)
        blocks = "#" * (i + 1)

        row = f"{spaces}{blocks}  {blocks}"
        print(row)
Ejemplo n.º 2
0
def inputHeight():
    while(True):
        print ("Input the column height(<23):", end = " ")
        colh = cs50.get_int();
        if colh > 0 and colh < 24:
            break
    return colh
Ejemplo n.º 3
0
def get_positive_int():
    while True:
        print("n is: ", end = "")
        n = cs50.get_int()
        if n >=1:
            break
    return n
Ejemplo n.º 4
0
def main():
    
    # Get credit card number and split string into integer digits in array
    print("Credit Card Number: ", end = "")
    cardInput = str(cs50.get_int())
    cardNumber = [int(i) for i in cardInput]
    
    # result from luhns algorithm
    total = luhn(cardNumber)
        
    # Valid credit cards final digit is 0
    if (total % 10 == 0):
        
        # Visa condition
        if cardInput[0] == "4":
            print("VISA")
            
        # Amex condition
        elif cardInput[0:2] == "34" or cardInput[0:2] == "37":
            print("AMEX")
        
        # Mastercard condition
        elif cardInput[0:2] == "51" or cardInput[0:2] == "52" or cardInput[0:2] == "53" or \
            cardInput[0:2] == "54" or cardInput[0:2] == "55":
            print("MASTERCARD")
    else:
        print("INVALID")
Ejemplo n.º 5
0
def getHeight():
    while True:
        print("Pyramid Height: ", end = "")
        height = cs50.get_int()
        
        if (height >= 0 and height < 23):
            break
    return height
Ejemplo n.º 6
0
def main():
    while True:
        print("Height: ", end = "")
        height = cs50.get_int()
        if height >= 0 and height <= 23:
            break
        
    for i in range(height):
        for j in range(height - i - 1):
            print(" ", end = "")
        for k in range(i+2):
            print("#", end = "")
        print("")
Ejemplo n.º 7
0
def main():
    # get int between 0 and 23 from user
    while True:
        print("Height: ", end="")
        height = cs50.get_int()
        if -1 < height < 24:
            break
    
    # calculate width of pyramid base
    base_width = height + 1
    
    # assign starting width of top row, then increment until base width reached
    for this_row in range(2, base_width + 1):
    
        # print pyramid row, right justified
        print((this_row * '#').rjust(base_width))
Ejemplo n.º 8
0
def main():

    # Get card number
    card_number = cs50.get_int("Number: ")

    # Create array of digits from card number
    card_digits = [int(digit) for digit in reversed(str(card_number))]

    # Calculate sum as specified in Luhn's algorithm
    luhn_sum = 0

    for i in range(len(card_digits)):

        # Sum the individual digits in 2 * digit for every other digit
        if i % 2 == 1:
            luhn_sum += sum(int(digit) for digit in str(2 * card_digits[i]))
        else:
            luhn_sum += card_digits[i]

    print(check_luhn_sum(reversed(card_digits), luhn_sum))
def main():
    n = str(get_int("Number: "))
    s, s1, c = 0, 0, 0

    for i in range(len(n) - 1, -1, -1):
        if (c % 2 == 1):
            s = s + digits((ord(n[i]) - ord('0')) * 2)
        else:
            s1 = s1 + (ord(n[i]) - ord('0'))
        c = c + 1

    if(((s + s1) % 10 != 0) or len(n) < 13 or len(n) > 16):
        print("INVALID")
    elif(n[0] == '4'):
        print("VISA")
    elif(n[0] == '5' and (n[1] in ['1', '2', '3', '4', '5'])):
        print("MASTERCARD")
    elif(n[0] == '3' and (n[1] == '4' or n[1] == '7')):
        print("AMEX")
    else:
        print("INVALID")
Ejemplo n.º 10
0
def get_height():
    while True:
        height = get_int("Height: ")
        if (height > 0) and (height < 9):
            break
    return height
from cs50 import get_int

n = get_int("Height: ")
while (n > 23 or n < 0):
    n = get_int("Height: ")

for i in range(1, n + 1):
    # Prints First triangle
    print(' ' * (n - i), end='')
    print('#' * (i + 1), end=''\n')
Ejemplo n.º 12
0
def main():
    num = get_int("Integer: ")
    print(f"hello, {num}")
Ejemplo n.º 13
0
import cs50

cardnum = cs50.get_int("Number: ")
while cardnum <= 0:
    cardnum = cs50.get_int("Number: ")

# length = len(str(cardnum))


def cardvalid(card):
    length = len(str(card))
    strcard = str(card)
    if length != 15 and length != 16 and length != 13:
        print("INVALID")
        return 1
    total = 0
    count = 1
    while card > 0:
        if count % 2 == 1:
            total = total + card % 10
        else:
            total = total + (2 * (card % 10)) % 10 + (2 * (card % 10)) // 10
        count += 1
        card = card // 10
    if total % 10 == 0:
        if length == 15 and strcard[0] == "3" and (strcard[1] == "4"
                                                   or strcard[1] == "7"):
            print("AMEX")
            return 0
        elif (length == 13 or length == 16) and strcard[0] == "4":
            print("VISA")
Ejemplo n.º 14
0
def get_height(min=1, max=8):
    """Prompt user for height value."""
    while True:
        height = get_int("Height: ")
        if height >= min and height <= max:
            return height
Ejemplo n.º 15
0
from cs50 import get_int


while True:
    # get height as integer
    credit_n = get_int("Number: ")
    if (credit_n > 0):
        break
n_as_strt = str(credit_n)

len_dig = len(n_as_strt)

first_two_dig = int(n_as_strt[0] + n_as_strt[1])

first_dig = int(str(credit_n)[0])

if ((first_two_dig == 34 or first_two_dig == 37) and len_dig == 15):
    print("AMEX")
elif ((first_two_dig == 51 or first_two_dig == 55) and len_dig == 16):
    print("MASTERCARD")
elif (first_dig == 4 and (len_dig == 13 or len_dig == 16)):
    print("VISA")
else:
    print("INVALID")

def get_positive_int(prompt):
     while True:
            n = get_int(prompt)
            if n > 0:
                break
            return n
Ejemplo n.º 17
0
from cs50 import get_int

# getting a number

while True:
    print("Give a positive integer not greater then 8")
    n = get_int()
    if n > 0 and n < 9:
        break

# printing bloxx
for i in range(n):
    for j in range(n - i - 1):
        print(" ", end="")

    for k in range(i + 1):
        print("#", end="")

    print()
Ejemplo n.º 18
0
from cs50 import get_int

# input height
height = 0
while height < 1 or height > 8:
    height = get_int("Height: ")

# print out pyramid
for i in range(height):
    for j in range(height + 2 + i + 1):
        if j < height - i - 1 or j == height + 0 or j == height + 1:
            print(' ', end='')
        else:
            print('#', end='')
    print()
Ejemplo n.º 19
0
def get_positive_int():
    while True:
        n = get_int("Height: ")
        if n > 0 and n <= 8:
            break
    return n
Ejemplo n.º 20
0
def get_positive_int(prompt):
    # Function to get positive integer not greater than 8
    while True:
        height = get_int(prompt)
        if height > 0 and height <= 8:
            return height
Ejemplo n.º 21
0
import sys

sys.path.insert(0, "../src")

import cs50

i = cs50.get_int("Input:  ")
print(f"Output: {i}")
Ejemplo n.º 22
0
from cs50 import get_int
from cs50 import get_string

# Prompt user for credit card number
credit_num = get_int("Number: ")

# Check if length of credit card number is valid

# Set variables needed for check
i = credit_num
length = 0

# Determine length of credit card number
while i >= 1:
    i = i / 10
    length += 1

# Check if length is valid
if length != 13 and length != 15 and length != 16:
    print("INVALID")

# Check Sum Calculation

# Set variables needed for check
j = credit_num
sum1 = 0
sum2 = 0

t = credit_num % 10
s = int(credit_num / 10)
print(s)
Ejemplo n.º 23
0
from cs50 import get_int
height = 0
while height < 1 or height > 8:
    height = get_int("Take me int number ")

for i in range(1, height + 1):
    print(" " * (height - i), end="")
    print("#" * i)
Ejemplo n.º 24
0
from cs50 import get_int
import numbers

# as long as the input is invalid, repromt the user
while True:

    # promt the user for height of the pyramid
    print("Please, give me height of the pyramid between 0 and 23: ", end="")
    height = get_int()

    if height >= 0 and height <= 23:
        break

######################################
#####Pyramid Construction#############
hashes = 2
spaces = height - 1
# print out the rows of the pyramid
for j in range(height):

    # print out spaces of the pyramid
    print(spaces * " ", end="")
    spaces -= 1

    # print out hashes
    print(hashes * "#", end="")
    hashes += 1

    # new line
    print()
Ejemplo n.º 25
0
from cs50 import get_int
c = get_int("Height:")

while c < 1 or c > 8:
    c = get_int("Height:")

for i in range(c):
    for j in range(c-1, i, -1):
        print(" ", end="")
    for o in range(i+1, 0, -1):
        print("#", end="")

    for p in range(i+1):

        if p==0:
            print("  ", end="")
        print("#", end="")
    print()

Ejemplo n.º 26
0
def get_positive_int(s):
    n = get_int(s)
    while True:
        if n > 0 and n < 9:
            return n
        n = get_int(s)
Ejemplo n.º 27
0
from cs50 import get_int


def pattern(n):

    k = 2 * n - 2

    for i in range(0, n):
        for j in range(0, k):
            print(end=" ")
        k = k - 2
        for j in range(0, i + 1):
            print("# ", end="")
        print("\r")


while True:
    n = get_int("Enter the height of the tower : ")
    if n > 0 and n < 9:
        break

pattern(n)
Ejemplo n.º 28
0
def getValidCardNumber():
    cardNumber = get_int("Number: ")
    while cardNumber <= 0:
        cardNumber = get_int("Number: ")
    return cardNumber
Ejemplo n.º 29
0
from cs50 import get_int

#ask the user for an input

height = 0

while(height > 8 or height < 1):
	height = get_int("Height: \n")



#prints the required pyramid

for i in range(1,height + 1):
	print(" " * (height - i), end="")
    print("#" * i, end="  ")
    print("#" * i)
Ejemplo n.º 30
0
from cs50 import get_int


x = get_int("x: ")
y = get_int("y: ")


print(f"x + y = {x + y}") # addition
print(f"x - y = {x - y}") # subtraction
print(f"x * y = {x * y}") # multiplication
print(f"x / y = {x / y}") # division
print(f"x / y = {x // y}") # Division | Which keeps the old behavior of always returning a truncated integer
print(f"x mod y = {x % y}") # Modulo
Ejemplo n.º 31
0
from cs50 import get_int

numbers = []

while True:
    number = get_int("Number: ")

    if not number:
        break

    if number not in numbers:
        numbers.append(number)

for number in numbers:
    print(number)
Ejemplo n.º 32
0
from cs50 import get_int
# get valid input
input = 0
while (input < 1 or input > 8):
    input = get_int("Height:\n")
# out put # * height i
for i in range(input):
    print(" " * (input - i - 1), end="")
    print("#" * (i + 1), end="  ")
    print("#" * (i + 1))
Ejemplo n.º 33
0
import cs50

#prompt for input
print("Number: ", end="")
cardnum = cs50.get_int()

n = len(str(cardnum))
if n != 13 and n != 15 and n != 16:
    print("INVALID")

else:
    cardnumodd = cardnum
    cardnumeven = cardnum // 10
    count = 0

    cardnum1 = []
    cardnum2 = []
    cardnum_multiply = []

    #sum of odd digits
    for i in range(0, (n + 1) // 2):
        cardnum1.insert(i, cardnumodd % 10)
        cardnumodd = cardnumodd // 100
        #print("odd: {}".format(cardnum1[i]))
    s_odd = sum(cardnum1)
    #print("s odd: {}".format(s_odd))

    #sum of other digits, x2
    for j in range(0, (n // 2)):
        cardnum2.insert(j, cardnumeven % 10)
        cardnumeven = cardnumeven // 100
Ejemplo n.º 34
0
def main():
    print("x is ", end="")
    x = cs50.get_int()
    print("x^2 is {}".format(square(x)))
Ejemplo n.º 35
0
from cs50 import get_int

#Get user input, introduce some variables
card = get_int("Credit Card Number: ")
digitize = card
count = len(str(abs(card)))
total = 0

#Store digits in list
digits = []
for i in range(count):
    digits.append(int(digitize % 10))
    digitize = (digitize - digits[i]) / 10

#Grab the first couple digits for checkin later
firstTwo = digits[count - 1] * 10 + digits[count - 2]
firstOne = digits[count - 1]

#Step 1: Multiply every other digit by 2,
#starting with the number’s second-to-last digit,
#then add those products' digits together
position = 1
productsSum = 0

for j in range(int(count / 2)):
    digits[position] = 2 * digits[position]
    for k in range(len(str(abs(digits[position])))):
        productsSum = productsSum + (int(digits[position] % 10))
        digits[position] = (digits[position] -
                            (int(digits[position] % 10))) / 10
    position = position + 2
Ejemplo n.º 36
0
import cs50

i = cs50.get_int()
print("hello, {}".format(i))
Ejemplo n.º 37
0
import cs50
import math

# # Initialise variables
num = cs50.get_int("Credit Card Number: ")

cardType = "INVALID"
total = 0

numDigits = math.floor(math.log10(abs(num))) + 1
first = int(num / pow(10, numDigits - 2))

# Check if number passes formula

for i in range(0, numDigits):
    if (i % 2):
        d = int(num % 10 * 2)
        if (d > 9):
            d = d - 9
        total += int(d)
    else:
        total += int(num % 10)
    num = int(num / 10)

if (first >= 51 and first <= 55 and numDigits == 16 and total % 10 == 0):
    cardType = "MASTERCARD"
if ((first == 34 or first == 37) and numDigits == 15 and total % 10 == 0):
    cardType = "AMEX"
if (first >= 40 and first <= 49 and (numDigits == 13 or numDigits == 16) and total % 10 == 0):
    cardType = "VISA"
print(cardType)
Ejemplo n.º 38
0
# get_int and print

from cs50 import get_int

age = get_int("What's your age?\n")
print(f"You are at least {age * 365} days old.")
Ejemplo n.º 39
0
# This is a program to implement Mario (more) as part of CS50 Problem Set 6
# Zach Sirera
# 8/2/2018 to 8/10/2018

import cs50

# Ask the user for the height of the Mario Pyramid
print("Height: ", end="")
height = cs50.get_int()

# Validate the height input
if height < 0 or height > 23:
    print("Height: ", end="")
    height = cs50.get_int()

# Carry out the printing iteration line by line
for i in range(height):
    # Print the initial spaces
    for j in range(height - i - 1):
        print(" ", end="")
    # Print the # characters for the left pyramid on each row
    for k in range(i + 1):
        print("#", end="")
    # Print the space between each pyramid
    print("  ", end="")
    # print the # characters for the right pyramid on each row
    for l in range(i + 1):
        print("#", end="")
    print("")
Ejemplo n.º 40
0
import cs50

# prompt user for x
print("x is ", end="")
x = cs50.get_int()

# prompt user for y
print("y is ", end="")
y = cs50.get_int()

# perform calculations for user
print("{} plus {} is {}".format(x, y, x + y))
print("{} minus {} is {}".format(x, y, x - y))
print("{} times {} is {}".format(x, y, x * y))
print("{} divided by {} is {}".format(x, y, x / y))
print("{} divided by {} (and floored) is {}".format(x, y, x // y))
print("remainder of {} divided by {} is {}".format(x, y, x % y))
Ejemplo n.º 41
0
from cs50 import get_int

x = get_int("x: ")
y = get_int("y: ")

#1

print("-" * 10)
print(x + y)
print("-" * 10)

print(f"x + y: {x + y}")
print(f"x - y: {x - y}")
print(f"x * y: {x * y}")
print(f"x / y: {x / y}")
print(f"x modulo y: {x % y}")

xIsEven = x % 2 == 0
xIsEvenLog = 'X is even' if xIsEven else 'X is not even'
print(xIsEvenLog)

# TASKS (8p)- calculate & print:
#0 Use alternative way of reading inputs - using library (0.5p)
#1 Perimeter & field of circles with given radius X for the first circle & Y for the second one. (1p)
#2 Find X & Y that satisfy: X is divisible by Y and both X & Y are even. (0.5p)
#3 Check if X is divisible by Y (do it in one line of code), print 'X is divisible by Y' or 'X is not divisible by Y'. (1p)
#Ad 3 Hint- use the "ternary operator" as we did calculating xIsEvenLog above.
#4 Add rounding for the above x/y operation. Round to 2 decimal points. Hint: look up in Google "python limiting number of decimals". (1p)
#5 Look at lab2-plot.py and create your own script which takes a number as an input and plots the same 3D wave but with different characteristics
# it's totally up to your imagination how do you want to amend the figure according to the input number (1p)
#6 Test your code. Check various edge cases. In other words: does your program (1, 3, 4 & 5)work for all input values?
Ejemplo n.º 42
0
from cs50 import get_int

while True:
    count = get_int("Count: ")
    if count > 0 and count < 9:
        break

# Prints each line/row
for i in range(count + 1):

    # Skip the first one cus idk how to change 'i' starting value in for loop
    if i == 0:
        continue

    # Print the appropriate spaces and hashes for the left side
    print(" " * (count - i), end="")
    print("#" * i, end="")

    # Print the appropriate spaces and hashes for the right side
    print("  ", end="")
    print("#" * i)
Ejemplo n.º 43
0
def get_height():
    while True:
        h = get_int("Height: ")
        if h > 0 and h < 9:
            break
    return h
Ejemplo n.º 44
0
import cs50

print("number: ", end='')
cardNumber = cs50.get_int()
currentNumber = cardNumber
sumDigits = 0
index = 0

while (currentNumber > 0):
    currentDigit = currentNumber % 10

    if index % 2 == 0:
        sumDigits += currentDigit
    else:
        currentDigit *= 2
        sumDigits += (currentDigit + currentDigit // 10) % 10

    if (currentNumber >= 10 and currentNumber < 100):
        firstTwoDigits = currentNumber
        firstDigit = currentNumber // 10

    index += 1
    currentNumber //= 10

validSum = sumDigits % 10 == 0

if (validSum):
    if firstTwoDigits in range(51, 56):
        print("MASTERCARD")
    elif firstTwoDigits == 34 or firstTwoDigits == 37:
        print("AMEX")
Ejemplo n.º 45
0
from cs50 import get_int

# Prompt user for a number for height
while True:
    h = get_int("Height (choose an integer between 1 to 23): ")
    if h >= 0 and h <= 23:
        break
n = 2
# Build pyramid
for i in range(h):
    for g in range(h - i - 1):
        print(" ", end="")
    for n in range(i + 2):
        print("#", end="")
    print()