migrate to git.charlotte.sh
This commit is contained in:
commit
fbd588721e
412 changed files with 13750 additions and 0 deletions
8
python-csi160/week04/Week-4Practice-Problems/part1.py
Normal file
8
python-csi160/week04/Week-4Practice-Problems/part1.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
number = int(input('Enter an integer: '))
|
||||
|
||||
# Determine odd or even
|
||||
|
||||
if number % 2 == 0:
|
||||
print("even")
|
||||
else:
|
||||
print("odd")
|
26
python-csi160/week04/Week-4Practice-Problems/part10.py
Normal file
26
python-csi160/week04/Week-4Practice-Problems/part10.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
def is_legal_bishop_move(initial_x, initial_y, final_x, final_y):
|
||||
"""Returns True / False whether a given move is a legal move for the Bishop.
|
||||
|
||||
This function assumes that there are no other pieces on the board.
|
||||
|
||||
:param initial_x: (int) Horizontal 1-8
|
||||
:param initial_y: (int) Vertical 1-8
|
||||
:param final_x: (int) Horizontal 1-8
|
||||
:param final_y: (int) Vertical 1-8
|
||||
:return: (bool) True / False if it is a legal move
|
||||
"""
|
||||
# Complete this function
|
||||
if initial_x == final_x and initial_y == final_y:
|
||||
return False
|
||||
return abs(initial_x - final_x) == abs(initial_y - final_y)
|
||||
|
||||
|
||||
# Leave this part for easily testing your function
|
||||
print('(4, 4, 3, 5) It is', is_legal_bishop_move(4, 4, 3, 5), 'that this is a legal move')
|
||||
print('(1, 4, 4, 7) It is', is_legal_bishop_move(1, 4, 4, 7), 'that this is a legal move')
|
||||
print('(5, 4, 2, 1) It is', is_legal_bishop_move(5, 4, 2, 1), 'that this is a legal move')
|
||||
print('(5, 4, 1, 1) It is', is_legal_bishop_move(5, 4, 1, 1), 'that this is a legal move')
|
||||
print('(5, 4, 6, 4) It is', is_legal_bishop_move(5, 4, 6, 4), 'that this is a legal move')
|
||||
print('(1, 1, 1, 1) It is', is_legal_bishop_move(1, 1, 1, 1), 'that this is a legal move')
|
||||
|
||||
|
12
python-csi160/week04/Week-4Practice-Problems/part2.py
Normal file
12
python-csi160/week04/Week-4Practice-Problems/part2.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
number1 = int(input('Enter an integer: '))
|
||||
number2 = int(input('Enter an integer: '))
|
||||
|
||||
|
||||
# Print the smaller number
|
||||
|
||||
|
||||
if number1 < number2:
|
||||
print(number1)
|
||||
else:
|
||||
print(number2)
|
9
python-csi160/week04/Week-4Practice-Problems/part3.py
Normal file
9
python-csi160/week04/Week-4Practice-Problems/part3.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
num = int(input('Enter a number: '))
|
||||
|
||||
# Print out result
|
||||
if num > 0:
|
||||
print("1")
|
||||
elif num < 0:
|
||||
print("-1")
|
||||
else:
|
||||
print("0")
|
7
python-csi160/week04/Week-4Practice-Problems/part4.py
Normal file
7
python-csi160/week04/Week-4Practice-Problems/part4.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
year = int(input('Enter the year: '))
|
||||
|
||||
# Prints Yes or No based on if year is in the 21st century
|
||||
if year >= 2001 and year <= 2100:
|
||||
print("YES")
|
||||
else:
|
||||
print("NO")
|
16
python-csi160/week04/Week-4Practice-Problems/part5.py
Normal file
16
python-csi160/week04/Week-4Practice-Problems/part5.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
def one_positive(num1, num2):
|
||||
"""Given two non-zero integers, returns True if exactly one of
|
||||
them is positive and returns False otherwise.
|
||||
|
||||
:param num1: non-zero integer
|
||||
:param num2: non-zero integer
|
||||
:return: True / False
|
||||
"""
|
||||
# Complete this function
|
||||
return (num1 > 0) ^ (num2 > 0)
|
||||
|
||||
|
||||
# Leave this part for easily testing your function
|
||||
print('(5, 7) It is', one_positive(5, 7), 'that only one of these numbers is positive')
|
||||
print('(-5, -7) It is', one_positive(-5, -7), 'that only one of these numbers is positive')
|
||||
print('(5, -7) It is', one_positive(5, -7), 'that only one of these numbers is positive')
|
27
python-csi160/week04/Week-4Practice-Problems/part6.py
Normal file
27
python-csi160/week04/Week-4Practice-Problems/part6.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
def ascending_digits(num):
|
||||
"""Given a three-digit integer X consisting of three different digits,
|
||||
returns True if its three digits are going in an ascending
|
||||
order from left to right and returns False otherwise.
|
||||
|
||||
:param num: three digit integer
|
||||
:return: True / False
|
||||
"""
|
||||
# Complete this function
|
||||
# Hint: assign variables for each digit first
|
||||
# then build the comparison
|
||||
|
||||
a = num // 100
|
||||
b = num % 100 // 10
|
||||
c = num % 10
|
||||
|
||||
ascending=False
|
||||
if a < b and b < c:
|
||||
ascending = True
|
||||
|
||||
return ascending
|
||||
|
||||
|
||||
# Leave this part for easily testing your function
|
||||
print('(136) It is', ascending_digits(136), 'that the digits are ascending')
|
||||
print('(462) It is', ascending_digits(462), 'that the digits are ascending')
|
||||
print('(823) It is', ascending_digits(823), 'that the digits are ascending')
|
20
python-csi160/week04/Week-4Practice-Problems/part7.py
Normal file
20
python-csi160/week04/Week-4Practice-Problems/part7.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
month = int(input('Enter the month: '))
|
||||
|
||||
|
||||
if month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12:
|
||||
print("31")
|
||||
elif month == 4 or month == 6 or month == 9 or month == 11:
|
||||
print("30")
|
||||
else:
|
||||
print("28")
|
||||
|
||||
'''
|
||||
month = month.lower()
|
||||
|
||||
if month == "january" or month == "march" or month == "may" or month == "july" or month == "august" or month == "october" or month == "december":
|
||||
print("31")
|
||||
elif month == "april" or month == "june" or month == "september" or month == "november":
|
||||
print("30")
|
||||
else:
|
||||
print("28")
|
||||
'''
|
18
python-csi160/week04/Week-4Practice-Problems/part8.py
Normal file
18
python-csi160/week04/Week-4Practice-Problems/part8.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
def is_legal_rook_move(initial_x, initial_y, final_x, final_y):
|
||||
"""Returns True / False whether a given move is a legal move for the Rook.
|
||||
|
||||
This function assumes that there are no other pieces on the board.
|
||||
|
||||
:param initial_x: (int) Horizontal 1-8
|
||||
:param initial_y: (int) Vertical 1-8
|
||||
:param final_x: (int) Horizontal 1-8
|
||||
:param final_y: (int) Vertical 1-8
|
||||
:return: (bool) True / False if it is a legal move
|
||||
"""
|
||||
# Complete this function
|
||||
return (initial_x != final_x) ^ (initial_y != final_y)
|
||||
|
||||
# Leave this part for easily testing your function
|
||||
print('(4, 4, 5, 5) It is', is_legal_rook_move(4, 4, 5, 5), 'that this is a legal move')
|
||||
print('(1, 4, 6, 4) It is', is_legal_rook_move(1, 4, 6, 4), 'that this is a legal move')
|
||||
print('(1, 4, 1, 7) It is', is_legal_rook_move(1, 4, 1, 7), 'that this is a legal move')
|
24
python-csi160/week04/Week-4Practice-Problems/part9.py
Normal file
24
python-csi160/week04/Week-4Practice-Problems/part9.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
def is_legal_king_move(initial_x, initial_y, final_x, final_y):
|
||||
"""Returns True / False whether a given move is a legal move for the King.
|
||||
|
||||
This function assumes that there are no other pieces on the board.
|
||||
|
||||
:param initial_x: (int) Horizontal 1-8
|
||||
:param initial_y: (int) Vertical 1-8
|
||||
:param final_x: (int) Horizontal 1-8
|
||||
:param final_y: (int) Vertical 1-8
|
||||
:return: (bool) True / False if it is a legal move
|
||||
"""
|
||||
# Complete this function
|
||||
|
||||
if initial_x == final_x and initial_y == final_y:
|
||||
return False
|
||||
return abs(initial_x - final_x) <= 1 and abs(initial_y - final_y) <= 1
|
||||
|
||||
|
||||
|
||||
|
||||
# Leave this part for easily testing your function
|
||||
print('(4, 4, 5, 5) It is', is_legal_king_move(4, 4, 5, 5), 'that this is a legal move')
|
||||
print('(1, 4, 6, 4) It is', is_legal_king_move(1, 4, 6, 4), 'that this is a legal move')
|
||||
print('(1, 4, 1, 3) It is', is_legal_king_move(1, 4, 1, 3), 'that this is a legal move')
|
Loading…
Add table
Add a link
Reference in a new issue