Professional Documents
Culture Documents
A N G M A N
#print here
import random
print("H A N G M A N")
print()
hangman = ['python', 'java', 'kotlin', 'javascript']
n = random.choice(hangman)
a = ["-" for x in range(len(n))]
aa = "".join(a)
b = "".join(a)
print(b)
letter = input("Input a letter: ")
save = set()
count = 0
j = 1
while j > 0:
if letter in save:
if j == 8:
print("No improvements")
print("You lost!")
break
else:
print("No improvements")
print()
print(b)
j += 1
elif letter not in n:
if j == 8:
print("That letter doesn't appear in the word")
print("You lost!")
break
else:
print("That letter doesn't appear in the word")
print()
print(b)
j += 1
else:
for i in n:
if i == letter:
a[count] = i
count += 1
b = "".join(a)
print()
print(b)
if b == n and b != aa:
print("""You guessed the word!
You survived!""")
break
count = 0
save.add(letter)
letter = input("Input a letter: ")
# print here
import random
print("H A N G M A N")
print()
hangman = ['python', 'java', 'kotlin', 'javascript']
n = random.choice(hangman)
a = ["-" for x in range(len(n))]
aa = "".join(a)
b = "".join(a)
print(b)
letter = input("Input a letter: ")
save_1 = set()
save_2 = set()
count = 0
j = 1
while j > 0:
if letter in save_2 or letter in save_1:
print("You've already guessed this letter")
print()
print(b)
elif len(letter) == 1 and letter not in "abcdefghijklmnopqrstuvwxyz":
print("Please enter a lowercase English letter")
print()
print(b)
elif len(letter) != 1:
print("You should input a single letter")
print()
print(b)
elif letter not in n:
if j == 8:
print("That letter doesn't appear in the word")
print("You lost!")
break
else:
print("That letter doesn't appear in the word")
print()
print(b)
save_2.add(letter)
j += 1
else:
for i in n:
if i == letter:
a[count] = i
count += 1
b = "".join(a)
print()
print(b)
if b == n and b != aa:
print("You guessed the word {}!".format(n))
print("You survived!")
break
count = 0
save_1.add(letter)
letter = input("Input a letter: ")
#print here
import random
def game():
print()
hangman = ['python', 'java', 'kotlin', 'javascript']
n = random.choice(hangman)
a = ["-" for x in range(len(n))]
aa = "".join(a)
b = "".join(a)
print(b)
letter = input("Input a letter: ")
save_1 = set()
save_2 = set()
count = 0
j = 1
while j > 0:
if letter in save_2 or letter in save_1:
print("You've already guessed this letter")
print()
print(b)
elif len(letter) == 1 and letter not in "abcdefghijklmnopqrstuvwxyz":
print("Please enter a lowercase English letter")
print()
print(b)
elif len(letter) != 1:
print("You should input a single letter")
print()
print(b)
elif letter not in n:
if j == 8:
print("That letter doesn't appear in the word")
print("You lost!")
break
else:
print("That letter doesn't appear in the word")
print()
print(b)
save_2.add(letter)
j += 1
else:
for i in n:
if i == letter:
a[count] = i
count += 1
b = "".join(a)
print()
print(b)
if b == n and b != aa:
print("""You guessed the word {}!
You survived!""".format(n))
break
count = 0
save_1.add(letter)
letter = input("Input a letter: ")
print("H A N G M A N")
while True:
menu = input('Type "play" to play the game, "exit" to quit: ')
if menu == "play":
game()
elif menu == "exit":
break
TIC_TAC_Toe
def xwin():
if (cells[0][0] == "X" and cells[0][1] == "X" and cells[0][2] == "X") \
or (cells[1][0] == "X" and cells[1][1] == "X" and cells[1][2] ==
"X") \
or (cells[2][0] == "X" and cells[2][1] == "X" and cells[2][2] ==
"X") \
or (cells[0][0] == 'X' and cells[1][0] == 'X' and cells[2][0] ==
'X') \
or (cells[0][1] == 'X' and cells[1][1] == 'X' and cells[2][1] ==
"X") \
or (cells[0][2] == 'X' and cells[1][2] == 'X' and cells[2][2] ==
"X") \
or (cells[0][0] == 'X' and cells[1][1] == 'X' and cells[2][2] ==
"X") \
or (cells[0][2] == 'X' and cells[1][1] == 'X' and cells[2][0] ==
"X"):
return True
else:
return False
def owin():
if (cells[0][0] == "O" and cells[0][1] == "O" and cells[0][2] == "O") \
or (cells[1][0] == "O" and cells[1][1] == "O" and cells[1][2] ==
"O") \
or (cells[2][0] == "O" and cells[2][1] == "O" and cells[2][2] ==
"O") \
or (cells[0][0] == 'O' and cells[1][0] == 'O' and cells[2][0] ==
'O') \
or (cells[0][1] == 'O' and cells[1][1] == 'O' and cells[2][1] ==
"O") \
or (cells[0][2] == 'O' and cells[1][2] == 'O' and cells[2][2] ==
"O") \
or (cells[0][0] == 'O' and cells[1][1] == 'O' and cells[2][2] ==
"O") \
or (cells[0][2] == 'O' and cells[1][1] == 'O' and cells[2][0] ==
"O"):
return True
else:
return False
cells = [[' ', ' ', ' '], [' ', ' ', ' '], [' ', ' ', ' ']]
print('---------')
print('| ' + cells[0][0] + ' ' + cells[0][1] + ' ' + cells[0][2] + ' |')
print('| ' + cells[1][0] + ' ' + cells[1][1] + ' ' + cells[1][2] + ' |')
print('| ' + cells[2][0] + ' ' + cells[2][1] + ' ' + cells[2][2] + ' |')
print('---------')
count = 0
count_x = 0
count_0 = 0
while True:
x, y = input('Enter the coordinates ').split()
if x not in '0123456789' or y not in '0123456789':
print("You should enter numbers!")
elif int(x) > 3 or int(x) < 1 or int(y) < 1 or int(y) > 3:
print("Coordinates should be from 1 to 3!")
elif cells[int(x) - 1][int(y) - 1] == "O" or cells[int(x) - 1][int(y) - 1]
== "X":
print("This cell is occupied! Choose another one!")
else:
if count % 2 == 0:
cells[int(x) - 1][int(y) - 1] = "X"
count_x += 1
else:
cells[int(x) - 1][int(y) - 1] = "O"
count_0 += 1
count += 1
print('---------')
print('| ' + cells[0][0] + ' ' + cells[0][1] + ' ' + cells[0][2] + ' |')
print('| ' + cells[1][0] + ' ' + cells[1][1] + ' ' + cells[1][2] + ' |')
print('| ' + cells[2][0] + ' ' + cells[2][1] + ' ' + cells[2][2] + ' |')
print('---------')
if owin() == True:
print("O wins")
break
elif xwin() == True:
print("X wins")
break
elif (count_0 + count_x == 9) and ((owin() == False) and (xwin() ==
False)):
print("Draw")
break
################################################################################
import math
calculate = input('''What do you want to calculate?
type "n" for number of monthly payments,
type "a" for annuity monthly payment amount,
type "p" for loan principal: ''')
if calculate == "n":
loan_principal = float(input('Enter the loan principal: '))
monthly_payment = float(input('Enter the monthly payment: '))
loan_interest = float(input('Enter the loan interest: '))
i = (loan_interest / (12 * 100))
n = math.ceil(math.log(abs(monthly_payment / (monthly_payment - i *
loan_principal)), 1 + i))
m = int(n // 12)
j = int(n % 12)
if m == 1:
if j == 1:
print("It will take {} year and {} month to repay this
loan!".format(m, int(j)))
else:
print("It will take {} year and {} months to repay this
loan!".format(m, int(j)))
elif m == 0:
print("It will take {} month to repay this loan!".format(int(j)))
elif j == 1:
print("It will take {} years and {} month to repay this loan!".format(m,
int(j)))
elif j == 0:
print("It will take {} years to repay this loan!".format(m))
else:
print("It will take {} years and {} months to repay this
loan!".format(m, int(j)))
elif calculate == "a":
loan_principal = float(input('Enter the loan principal: '))
number_periods = float(input('Enter the number of periods: '))
loan_interest = float(input('Enter the loan interest: '))
i = (loan_interest / (12 * 100))
pawer = math.pow(1 + i, number_periods)
x = (i * pawer) / (pawer - 1)
annuity_payment = loan_principal * x
print('Your loan principal = {}!'.format(math.ceil(annuity_payment)))
else:
annuity_payment = float(input('Enter the annuity payment: '))
number_periods = float(input('Enter the number of periods: '))
loan_interest = float(input('Enter the loan interest: '))
i = (loan_interest / (12 * 100))
pawer = math.pow(1 + i, number_periods)
x = (i * pawer) / (pawer - 1)
loan_principal = annuity_payment / x
print('Your loan principal = {}!'.format(round(loan_principal)))
####################################################################
HONEST CALCULATOR
def isDigit(z):
try:
float(z)
return True
except ValueError:
return False
while True:
print(msg_0)
calc = input().split(' ')
x = calc[0]
operation = calc[1]
y = calc[2]
memory = 0
while True:
print(msg_0)
calc = input().split()
try:
if calc[0] != 'M':
calc[0] = float(calc[0])
else:
calc[0] = memory
if calc[2] != 'M':
calc[2] = float(calc[2])
else:
calc[2] = memory
except ValueError:
print(msg_1)
continue
print(msg_4)
store_result = input()
if store_result == 'y':
memory = result
print(msg_5)
continue_calc = input()
if continue_calc == 'y':
continue
elif continue_calc == 'n':
break
else:
print(msg_2)
#Not correct
memory = 0
while True:
print(msg_0)
calc = input().split()
try:
if calc[0] != 'M':
calc[0] = float(calc[0])
else:
calc[0] = memory
if calc[2] != 'M':
calc[2] = float(calc[2])
else:
calc[2] = memory
except ValueError:
print(msg_1)
continue
print(msg_4)
store_result = input()
if store_result == 'y':
memory = result
print(msg_5)
continue_calc = input()
if continue_calc == 'y':
continue
elif continue_calc == 'n':
break
else:
print(msg_2)