You are on page 1of 16

A N G M A N

# Write your code here


print("""H A N G M A N
The game will be available soon.""")

# Write your code here


print("H A N G M A N")
a = input()
if a == "python":
    print("You survived!")
else:
    print("You lost!")

# Write your code here


import random
print("H A N G M A N")
hangman = ['python', 'java', 'kotlin', 'javascript']
n = random.choice(hangman)
geuse = input("Guess the word: ")
if geuse == n:
    print("You survived!")
else:
    print("You lost!")

# Write your code here


import random
print("H A N G M A N")
hangman = ['python', 'java', 'kotlin', 'javascript']
n = random.choice(hangman)
a = n[:3]
word_ = len(n) - 3
s = "-" * word_
b = "{}{}".format(a, s)
geuse = input("Guess the word {}: ".format(b))
if geuse == n:
    print("You survived!")
else:
    print("You lost!")

# Write your code 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))]
b = "".join(a)
print(b)
letter = input("Input a letter: ")
count = 0
j = 1
while j < 8:
    if letter not in n:
        print("That letter doesn't appear in the word")
        print()
        print(b)
    else:
        for i in n:
            if i == letter:
                a[count] = i
            count += 1
        b = "".join(a)
        print()
        print(b)
        count = 0
    letter = input("Input a letter: ")
    j += 1
print()
print("""Thanks for playing!
We'll see how well you did in the next stage""")

#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

a = input("Enter cells: ")


print("---------")
print('''
| {} {} {} |
| {} {} {} |
| {} {} {} |'''.format(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]))
print("---------")

a = input("Enter cells: ")


print("---------")
print('''
| {} {} {} |
| {} {} {} |
| {} {} {} |'''.format(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]))
print("---------")
X = a.count("X")
O = a.count("O")
if O + 1 < X or X + 1 < O:
    print('Impossible')
else:
    if (a[0] == "X" and a[3] == "X" and a[6] == "X") \
            or (a[1] == "X" and a[4] == "X" and a[7] == "X") \
            or (a[2] == "X" and a[5] == "X" and a[8] == "X"):
        if (a[0] == "O" and a[3] == "O" and a[6] == "O") \
                or (a[1] == "O" and a[4] == "O" and a[7] == "O") \
                or (a[2] == "O" and a[5] == "O" and a[8] == "O"):
            print("Impossible")
        else:
            print("X wins")
    elif (a[0] == "O" and a[3] == "O" and a[6] == "O") \
            or (a[1] == "O" and a[4] == "O" and a[7] == "O") \
            or (a[2] == "O" and a[5] == "O" and a[8] == "O"):
        print("O wins")

    elif a[:3] == "OOO" or a[3:6] == "OOO" or a[6:9] == "OOO":


        if a[:3] == "XXX" or a[3:6] == "XXX" or a[6:9] == "XXX":
            print("Impossible")
        else:
            print("O wins")

    elif a[:3] == "XXX" or a[3:6] == "XXX" or a[6:9] == "XXX":


        print("X wins")
    elif (a[0] == "O" and a[4] == "O" and a[8] == "O") or (a[2] == "O" and a[4]
== "O" and a[6] == "O"):
        print("O wins")
    elif (a[0] == "X" and a[4] == "X" and a[8] == "X") or (a[2] == "X" and a[4]
== "X" and a[6] == "X"):
        print("X wins")
    elif "_" not in a:
        print("Draw")
    else:
        print("Game not finished")

a = input("Enter cells: ")


cells = [[a[0], a[1], a[2]], [a[3], a[4], a[5]], [a[6], a[7], a[8]]]
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('---------')
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:
        cells[int(x) - 1][int(y) - 1] = "X"
        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('---------')
        break

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

loan_principal = int(input("Enter the loan principal: "))


choise = input('''What do you want to calculate?
type "m" - for number of monthly payments,
type "p" - for the monthly payment: ''')
if choise == "m":
    monthly_payment = int(input('Enter the monthly payment: '))
    month = loan_principal // monthly_payment
    if loan_principal % monthly_payment != 0:
        month += 1
        print("It will take {} months to repay the loan".format(month))
    else:
        if loan_principal // monthly_payment == 1:
            print("It will take {} month to repay the loan".format(month))
        else:
            print("It will take {} months to repay the loan".format(month))

elif choise == "p":


    number_months = int(input('Enter the number of months: '))
    payment = loan_principal // number_months
    if loan_principal % number_months != 0:
        payment += 1
        last_payment = loan_principal - (number_months - 1) * payment
        print("Your monthly payment = {} and the last payment =
{}.".format(payment, last_payment))
    else:
        print("Your monthly payment = {}".format(payment))

################################################################################

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

# write your code here


msg_0 = "Enter an equation"
msg_1 = "Do you even know what numbers are? Stay focused!"
msg_2 = "Yes ... an interesting math operation. You've slept through all classes,
haven't you?"

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]

    if not (isDigit(x) and isDigit(y)):


        print(msg_1)
    elif operation not in  '+-*/':
        print(msg_2)
    else:
        break
msg_0 = "Enter an equation"
msg_1 = "Do you even know what numbers are? Stay focused!"
msg_2 = "Yes ... an interesting math operation. You've slept through all classes,
haven't you?"
def check(z):
    try:
        float(z)
        return True
    except ValueError:
        return False
while True:
    print(msg_0)
    calc = input().split(' ')
    x = calc[0]
    oper = calc[1]
    y = calc[2]
    if check(x) == False or check(y) == False:
        print(msg_1)
    else:
        if oper in '+-*/':
            x = float(x)
            y = float(y)
            if oper == "+":
                result = x + y
                print(result)
            elif oper == "-":
                result = x - y
                print(result)
            elif oper == "*":
                result = x * y
                print(result)
            elif oper == "/":
                while y != 0:
                    result = x / y
                    print(result)
                    break
                else:
                    print("Yeah... division by zero. Smart move...")
                    continue
            break
        else:
            print(msg_2)

msg_0 = "Enter an equation"


msg_1 = "Do you even know what numbers are? Stay focused!"
msg_2 = "Yes ... an interesting math operation. You've slept through all classes,
haven't you?"
msg_3 = "Yeah... division by zero. Smart move..."
msg_4 = "Do you want to store the result? (y / n):"
msg_5 = "Do you want to continue calculations? (y / n):"

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

    if calc[1] in ['+', '-', '*', '/']:


        if calc[1] == '+':
            result = float(calc[0]) + float(calc[2])
        elif calc[1] == '-':
            result = float(calc[0]) - float(calc[2])
        elif calc[1] == '*':
            result = float(calc[0]) * float(calc[2])
        elif calc[1] == '/':
            if calc[2] != 0:
                result = float(calc[0]) / float(calc[2])
            else:
                print(msg_3)
                continue
        print(result)

        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

msg_0 = "Enter an equation"


msg_1 = "Do you even know what numbers are? Stay focused!"
msg_2 = "Yes ... an interesting math operation. You've slept through all classes,
haven't you?"
msg_3 = "Yeah... division by zero. Smart move..."
msg_4 = "Do you want to store the result? (y / n):"
msg_5 = "Do you want to continue calculations? (y / n):"

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

    if calc[1] in ['+', '-', '*', '/']:


        if calc[1] == '+':
            result = float(calc[0]) + float(calc[2])
        elif calc[1] == '-':
            result = float(calc[0]) - float(calc[2])
        elif calc[1] == '*':
            result = float(calc[0]) * float(calc[2])
        elif calc[1] == '/':
            if calc[2] != 0:
                result = float(calc[0]) / float(calc[2])
            else:
                print(msg_3)
                continue
        print(result)

        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)

You might also like