Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p2 #6

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open

p2 #6

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions 02-TypesAndVariables/stare/task10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
x = input("Enter first number: ")
y = input("Enter second number: ")

x = int(x)
y = int (y)

print(f"the first number plus the second is {x+y}")
6 changes: 6 additions & 0 deletions 02-TypesAndVariables/stare/task11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name = input("Enter your name:")
age = input("Enter your age:")
height = input("Enter your hight")
age = int(age)
height = int(height)
print (f"My name is {name}, I\'m {age} years old, and my height is {height}")
12 changes: 12 additions & 0 deletions 02-TypesAndVariables/stare/task7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
n1 = 5
n2 = 1
n3 = 8
n4 = 6
n5 = 3
a = n1+n2+n3+n4+n5
print (a)
b = n1**2+n2**2+n3**2+n4**2+n5**2
print (b)
c = n3 / n5
print (c)
print (n3 == n4)
9 changes: 9 additions & 0 deletions 02-TypesAndVariables/stare/task8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from re import X


x = 7
y = 34
z = x
x = y
y = z
print(x, y)
3 changes: 3 additions & 0 deletions 02-TypesAndVariables/stare/task9.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = input("Enter your name: ")
surname = input("Enter your surname: ")
print(f"your name is {name} and surname is {surname}")
10 changes: 10 additions & 0 deletions 02-TypesAndVariables/t18.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
x = 7
y = 34
print(f'Value of x: {x}')
print(f'Value of y: {y}')
z = 0
z = x
x = y
y = z
print(f'Value of x after swapping: {x}')
print(f'Value of y after swapping; {y}')
4 changes: 4 additions & 0 deletions 02-TypesAndVariables/t19.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
side = int(input("Enter cube side: "))
print(f"Cube side: {side}")
print(f'Cube volume: {side**3}')
print(f"Cube surface area: {side**2*6}")
4 changes: 4 additions & 0 deletions 02-TypesAndVariables/t20.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
a = int(input("Number one: "))
b = int(input("Number two: "))
print(f"Division result: {a/b}")
print(f"Remainder: {a%b}")
5 changes: 5 additions & 0 deletions 02-TypesAndVariables/t21.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import math
height = int(input("Ender your height: "))
feet = int(height/30.48)
inches = math.ceil((height-30.48*feet)*0.39)
print(f'I am {height}cm tall, i.e {feet} feet and {inches} inches')
3 changes: 3 additions & 0 deletions 02-TypesAndVariables/t22.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a = 3
b = 5
print(f'{a} - {b} = {a-b}')
7 changes: 7 additions & 0 deletions 02-TypesAndVariables/t23.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
a = float(input("Enter a:"))
b = float(input("Enter b:"))
c = float(input("Enter c:"))
s = (a+b+c)/2
area = (s*(s - a)*(s - b)*(s - c))**(1/2)
print(f'Triangle area: {area}')
print(f'Triangle cimcumference: {a+b+c}')
2 changes: 2 additions & 0 deletions 02-TypesAndVariables/t24.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
regnum = input('Enter vehicle registration number: ')
print(regnum[:2] == 'KR' or regnum[:2] == 'KK')
8 changes: 8 additions & 0 deletions 02-TypesAndVariables/t25.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def paying_taxes():
taxes = True
age = int(input("Enter age: "))
if age > 26:
taxes = False
return f"Exemption from paying taxes: {taxes}"

print(paying_taxes())
11 changes: 11 additions & 0 deletions 02-TypesAndVariables/t26.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def is_even():
number = int(input("Enter number: "))
if number%2 == 0:
check = True
else:
check = False

return f"Number is even: {check}"


print(is_even())
10 changes: 10 additions & 0 deletions 02-TypesAndVariables/t27.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def in_range():
num = int(input("Enter number: "))
if num >= -10 and num<= 10:
result = True
else:
result = False

return f'Number ub range <-10, 10>: {result}'

print(in_range())
17 changes: 17 additions & 0 deletions 02-TypesAndVariables/t28.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def cBMI():
height = float(input("Enter your height: "))
weight = float(input("Enter your weight: "))
bmiindex = weight/(height/100)**2.0
if bmiindex >=18.5 and bmiindex <= 24.99:
correct_weight = True
else:
correct_weight = False
result = f'Your BMI index: {bmiindex}\nCorrect weight: {correct_weight}'

return result





print(cBMI())
9 changes: 9 additions & 0 deletions 02-TypesAndVariables/t29.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import random
def rand():
roll_one = random.randint(1,6)
roll_two = random.randint(1,6)
roll_three = random.randint(1,6)
sum = roll_one + roll_two + roll_three
result = f'roll one = {roll_one}\nroll two = {roll_two}\nroll three = {roll_three}\nsum = {sum}'
return result
print(rand())
15 changes: 15 additions & 0 deletions 02-TypesAndVariables/t30.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import random


def is_special():
number = random.randint(1,6)
if number == 1 or number == 6:
special_num = True
else:
special_num = False
result = f'Dice rolled: {number}\nSpecial number: {special_num}'

return result


print(is_special())
14 changes: 14 additions & 0 deletions 02-TypesAndVariables/t31.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import random

def challange():
number = int(input("Guess number: "))
randnum = random.randint(1,6)
if randnum == number:
result = True
else:
result = False

return result


print(challange())
9 changes: 9 additions & 0 deletions 02-TypesAndVariables/t32.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def cVAT():
amount = float(input("Enter amount: "))
vat = round(0.23 * amount, 2)
result = f"Amount: {amount} \nVAT 23%: {vat}"

return result


print(cVAT())
10 changes: 10 additions & 0 deletions 02-TypesAndVariables/t33.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def password():
password = input('Enter password: ')
if len(password) < 8:
reslt = False
else:
reslt = True
result = f"Password is valid: {reslt}"
return result

print(password())
12 changes: 12 additions & 0 deletions 02-TypesAndVariables/t34.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def check_speed():
speed = int(input("Enter vehicle speed: "))
if speed <= 140 and speed >= 40:
check = True
else:
check = False

result = f"Speed is valid: {check}"

return result

print(check_speed())
12 changes: 12 additions & 0 deletions 02-TypesAndVariables/t35.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def tree_cut():
circumference = float(input("Enter tree circumference: "))
diameter = circumference/3.14
if diameter >= 50:
check = True
else:
check = False
result = f"Tree can be cut down: {check}"

return result

print(tree_cut())
9 changes: 9 additions & 0 deletions 02-TypesAndVariables/t36.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def spread():
buyeur = round(float(input("Bank buys EUR: ")), 4)
selleur = round(float(input("Bank sell EUR: ")), 4)
spread = round(selleur - buyeur, 4)
result = f'Spread: {spread}'

return result

print(spread())
14 changes: 14 additions & 0 deletions 02-TypesAndVariables/t37.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def slicing():
personel_data = "Mr. John May, born on 1998-02-16"
name = personel_data[4:8]
surname = personel_data[9:12]
initials = personel_data[4] + personel_data[9]
born = personel_data[22:]
result = f'Name: {name}\nSurname: {surname}\nInitials: {initials}\nBorn: {born}'

return result




print(slicing())
7 changes: 7 additions & 0 deletions 02-TypesAndVariables/t38.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def telephone():
num = input("Enter phone number: ")
result = num[:3]+"-"+ num[3:6]+"-"+num[6:]
return result


print(telephone())
12 changes: 12 additions & 0 deletions 02-TypesAndVariables/t39.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def discount():
price = float(input("Enter price: "))
discount = int(input("Enter discount: "))
price_with = round(price - price*(discount/100), 2)
reduction = round(price - price_with, 2)

result = f'Price with discount: {price_with}\nReduction: {reduction}'

return result


print(discount())
7 changes: 7 additions & 0 deletions 02-TypesAndVariables/t40.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def credit_num():
number = input("Enter credit card number: ")
card_number = number[:4]+" "+number[4:8]+" "+number[8:12]+" "+number[12:]

return f'Card number: {card_number}'

print(credit_num())
8 changes: 8 additions & 0 deletions 02-TypesAndVariables/t41.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def binandhex():
num = int(input("Enter number: "))
bina = bin(num)
hexa = hex(num)
return f'Binary number: {bina}\nHexadecimal number: {hexa}'


print(binandhex())
16 changes: 16 additions & 0 deletions 02-TypesAndVariables/t42.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def btod():
binary = input("Enter binary number: ")
result = 0
if binary[0] == '1':
result+= 8
if binary[1] == '1':
result+= 4
if binary[2] == '1':
result+= 2
if binary[3] == '1':
result+= 1

return f'Binart number in decimal notation: {result}'


print(btod())
10 changes: 10 additions & 0 deletions 02-TypesAndVariables/t43.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def unicode():
name = input("Enter name: ")
result = ""
for i in name:
result += i+"("+str(ord(i))+ ") "

return result


print(unicode())
Binary file added 02-TypesAndVariables/~$-TypesAndVariables.docx
Binary file not shown.
17 changes: 17 additions & 0 deletions 03-ControlStructures/spr2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def f(x,y,z):
if x > y and y > z and x > z:
print(x-z)
elif x > y and y < z and x > z:
print(x-y)
elif y > x and x < z and z < y:
print(y-x)
elif y > x and x > z and y > z:
print(y-z)
elif z > x and x < z and y < x:
print(z-y)
else:
print(z-x)

f(17,15,19)
f(29,14,19)

11 changes: 11 additions & 0 deletions 03-ControlStructures/spr3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def f(pause):
length = len(pause)
for i in range(0, length):
if pause[i] == " ":
pass
else:
print(pause[i], end = "")
print()

f("1 2 3 4 5")
f("aa bb cc dd")
16 changes: 16 additions & 0 deletions 03-ControlStructures/spr4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def f(palindrom):
lenght = len(palindrom)
if palindrom[0] == palindrom[-1]:
pass

for i in range(1,int(lenght/2)):
if palindrom[i] == palindrom[-i+1]:
pass
else:
print ("False")
return False

f("abcdefgfedcba")
f("radar")
f("abcdecdba")
f("12345432")
Loading