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

Zadania #10

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions 02-TypesAndVariables/ex1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = input('Enter your name:')
print ('Hello', name)
4 changes: 4 additions & 0 deletions 02-TypesAndVariables/ex2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
x = float(input('Enter Hours: '))
y = float(input('Enter Rate: '))
z = x * y
print ('Pay:',z)
8 changes: 8 additions & 0 deletions 02-TypesAndVariables/ex3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
width = 17
height = 12.0
x = width//2 #variable type int
y = width/2.0 #variable type float
z = height/3 #variable type float
a = 1 + 2 * 5 #variable type int
print (x,'\n',y,'\n' ,z,'\n',a)
print (type(x),'\n',type(y),'\n' ,type(z),'\n',type(a))
3 changes: 3 additions & 0 deletions 02-TypesAndVariables/ex4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
celcius = float (input('Enter temperature in Celcius:'))
fahrenheit = (celcius * 2) + 30
print ('Temperature in Fahrenheit:', fahrenheit)
1 change: 1 addition & 0 deletions 02-TypesAndVariables/hello_world.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print ('Hello World')
6 changes: 6 additions & 0 deletions 02-TypesAndVariables/zadanie10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name = 'Gabriela'
age = 19
height = 168
years = 25
s = f'My name is {name}, I am {age} years old, and my height is {height} cm. In 6 years I will be {years} years old.'
print(s)
6 changes: 6 additions & 0 deletions 02-TypesAndVariables/zadanie11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
father = 5000
mother = 8000
number = 4

s = f'Enter father’s income: {father} Enter mother’s income:{mother} Enter number of people in family: {number} Total income: {father + mother} Income per person: {(father+mother)/number}'
print (s)
2 changes: 2 additions & 0 deletions 02-TypesAndVariables/zadanie13.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
side = int(input('Enter cube side: '))
print(f"The surface area of a cube with side {side} is {side**2 * 6}")
4 changes: 4 additions & 0 deletions 02-TypesAndVariables/zadanie18.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
x = 7
y = 34
x, y = y, x
print(f'Value of x after swapping: {x} Value of y after swapping: {y}')
3 changes: 3 additions & 0 deletions 02-TypesAndVariables/zadanie19.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
side=float(input('cube side: '))
print(f'cube volume: {side**3}')
print(f'cube surface area: {side**2*6}')
4 changes: 4 additions & 0 deletions 02-TypesAndVariables/zadanie20.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}')
7 changes: 7 additions & 0 deletions 02-TypesAndVariables/zadanie21.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
height_in_cm = float(input("Enter your height in centimeters: "))

height_in_inches = height_in_cm / 2.54
height_in_feet = int(height_in_inches // 12)
remaining_inches = int(height_in_inches % 12)

print(f"I am {height_in_cm}cm tall, i.e. {height_in_feet} feet and {remaining_inches} inches.")
3 changes: 3 additions & 0 deletions 02-TypesAndVariables/zadanie22.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}')
10 changes: 10 additions & 0 deletions 02-TypesAndVariables/zadanie23.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import math
a=float(input('First side:'))
b=float(input('Second side:'))
c=float(input('Third side:'))
s=(a+b+c)/2
if ((a + b) > c and (a + c) > b and (b + c) > a) :
print(f'Triangle area: {round(math.sqrt(s*(s-a)*(s-b)*(s-c)), 2)}')
print(f'Triangle circumference: {a+b+c}')
else :
print("Such triangle doesn't exist")
8 changes: 8 additions & 0 deletions 02-TypesAndVariables/zadanie24.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
s=str(input("Enter vehicle registration number: "))
if s[0:2] == "KR" or s [0:2] == "KK" :
b = True
print('Car from Kraków:', b )
else :
c = False
print('Car from Kraków:', c)

7 changes: 7 additions & 0 deletions 02-TypesAndVariables/zadanie25.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
a=int(input('Enter your age: '))
if a <= 26 :
b = True
print(f'Exemption from paying taxes: {b}')
else :
b = False
print(f'Exemption from paying taxes: {b}')
7 changes: 7 additions & 0 deletions 02-TypesAndVariables/zadanie26.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
a=int(input('Enter number: '))
if a%2 == 0 :
b = True
print(f'Number is even: {b}')
else :
b =False
print(f'Number is even: {b}')
9 changes: 9 additions & 0 deletions 02-TypesAndVariables/zadanie27.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
a = float(input('Enter number: '))
b = range(-10, 11)
if a in b:
c = True
print(f'Number in the range <-10,10>: {c}')
else :
c = False
print(f'Number in the range <-10,10>: {c}')

10 changes: 10 additions & 0 deletions 02-TypesAndVariables/zadanie28.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
a = float(input('Enter your height in cm: '))
b = float(input('Enter your weight in kg: '))
d = round(b/(a/100)**2, 2)
print(f'Your BMI index:{d}')
if (d <= 24.9 and d >= 18.5 ) :
c = True
print(f'Correct weight: {c}')
else :
c = False
print(f'Correct weight: {c}')
6 changes: 6 additions & 0 deletions 02-TypesAndVariables/zadanie29.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import random
a = random.randint(1,6)
b = random.randint(1,6)
c = random.randint(1,6)
print (f'Values diced in 3 rolls: {a}, {b}, {c}')
print (f'Sum of values diced in 3 rolls: {a + b + c}')
9 changes: 9 additions & 0 deletions 02-TypesAndVariables/zadanie30.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import random
a = random.randint(1, 6)
print(f'Dice rolled: {a}')
if a == 1 or a ==6 :
b = True
print(f'Special number:{b}')
else :
b = False
print(f'Special number: {b}')
9 changes: 9 additions & 0 deletions 02-TypesAndVariables/zadanie31.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import random
a = random.randint(1, 6)
b = int(input('Enter number between 1 and 6: '))
if a == b:
c = True
print(c)
else :
c = False
print(c)
3 changes: 3 additions & 0 deletions 02-TypesAndVariables/zadanie32.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a = float(input('Amount: '))
print (f'Amount: {round(a,2)}')
print (f'VAT 23%: {round(a*0.23, 2)}')
7 changes: 7 additions & 0 deletions 02-TypesAndVariables/zadanie33.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
a = input('Enter password: ')
if len(a) >= 8 :
b = True
print(f'Password is valid: {b}')
else :
b = False
print(f'Password is valid: {b}')
7 changes: 7 additions & 0 deletions 02-TypesAndVariables/zadanie34.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
a = float((input('Enter vehicle speed: ')))
if a >= 40 and a <= 140:
c = True
print(f'Speed is valid: {c}')
else :
c = False
print(f'Speed is valid: {c}')
8 changes: 8 additions & 0 deletions 02-TypesAndVariables/zadanie35.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
a = float(input('Enter tree circumference in cm: '))
b = a / (2*3.14)
if (2*b) >= 50 :
c = True
print(f'Tree can be cut down: {c}')
else :
c = False
print(f'Tree can be cut down: {c}')
4 changes: 4 additions & 0 deletions 02-TypesAndVariables/zadanie36.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from decimal import*
a = float(input('Bank buys EUR: '))
b = float(input('Bank sells EUR: '))
print(f'Spread: {round(Decimal(abs(a-b)), 4)}')
6 changes: 6 additions & 0 deletions 02-TypesAndVariables/zadanie37.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
personal_data = 'Mr. John May, born on 1998-02-16'
print(f'Description: {personal_data}')
print(f'Name: {personal_data[4:8]}')
print(f'Surname: {personal_data[9:12]}')
print(f'Initials: {personal_data[4]}{personal_data[9]}')
print(f'Born: {personal_data[22:32]}')
2 changes: 2 additions & 0 deletions 02-TypesAndVariables/zadanie38.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a = input('Enter phone number: ')
print(f'Phone number: {a[0:3]}-{a[3:6]}-{a[6:9]}')
6 changes: 6 additions & 0 deletions 02-TypesAndVariables/zadanie39.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a = float(input('Enter price: '))
b = float(input('Enter discount(%): '))
print (f'Price: {a}')
print(f'Discount: {b}%')
print(f'Price with discount: {round((1-b/100)*a, 2)}')
print(f'Reduction: {round(a-(1-b/100)*a, 2)}')
2 changes: 2 additions & 0 deletions 02-TypesAndVariables/zadanie40.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a = input('Enter credit card number: ')
print(f'Credit card number: {a[0:4]} {a[4:8]} {a[8:12]} {a[12:16]}')
3 changes: 3 additions & 0 deletions 02-TypesAndVariables/zadanie41.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a = int(input('Enter number: '))
print(f'Binary number: {bin(a)}')
print(f' Hexadecimal: {hex(a)}')
9 changes: 9 additions & 0 deletions 02-TypesAndVariables/zadanie42.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
a = (input('Enter binary number: '))
if len(a) <= 4 :
b = int(a[0])
c = int(a[1])
d = int(a[2])
e = int(a[3])
print(f'Binary number in decimal notation: {(b*2**3) + (c*2**2) + (d*2**1) + (e*2**0)}')
else :
print("You can only enter four-digit number!")
5 changes: 5 additions & 0 deletions 02-TypesAndVariables/zadanie43.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = 'Gabrysia'
print(name)
for i in name:
numeric_representation = ord(i)
print(f'{i}({numeric_representation})',end=' ')
6 changes: 6 additions & 0 deletions 02-TypesAndVariables/zadanie8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
number1 = 71
number2 = 14
result = number1 + number2
print('Number 1:', number1)
print('Number 2:', number2)
print('The result of summation:', result)
13 changes: 13 additions & 0 deletions 02-TypesAndVariables/zadanie9.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
n1 = 5
n2 = 1
n3 = 8
n4 = 6
n5 = 3
sum = n1 + n2 + n3 + n4 + n5
print('Sum of all variables:', sum)
x = n1**2 + n2**2 + n3**2 + n4**2 + n5**2
print('Sum of all squared variables:', x)
y = n3 / n5
print('Quotient of third and fifth variable:', y)
z = n3 == n4
print('Third variable is equal to forth variable:', z)
7 changes: 7 additions & 0 deletions 03-ControlStructures/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sum = 0
number = 1
while number <= 5:
sum = sum + number
number = number + 1
message = f"Sum of numbers in <1,5> is {sum}"
print(message)
5 changes: 5 additions & 0 deletions 03-ControlStructures/zadanie10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
number = int(input('Enter number: '))
if number >= 0:
print(f'|{number}| = {number}')
else:
print(f'|{number}| = {-number}')
5 changes: 5 additions & 0 deletions 03-ControlStructures/zadanie11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
a = int(input('Enter number: '))
if a%2 == 0:
print('Number is even')
else:
print('Number is odd')
8 changes: 8 additions & 0 deletions 03-ControlStructures/zadanie12.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
first_name = str(input('Enter first person name: '))
first_age = int(input('Enter fist person age: '))
second_name = str(input('Enter second person name: '))
second_age = int(input('Enter second person age: '))
if first_age >= 18 and second_age >= 18:
print(f'Both {first_name} and {second_name} are adults.')
else:
print("At least one of them isn't adult.")
6 changes: 6 additions & 0 deletions 03-ControlStructures/zadanie13.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a = int(input('Enter number 1: '))
b = int(input('Enter number 2: '))
if (a >= 0 or b >= 0):
print(f'At least one of entered numbers {a} and {b} is not negative')
else:
print(f'Both of numbers are negative')
4 changes: 4 additions & 0 deletions 03-ControlStructures/zadanie14.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
i = 1
while i <= 5:
print('Practice makes perfect!!')
i = i + 1
2 changes: 2 additions & 0 deletions 03-ControlStructures/zadanie15.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
for i in range(5):
print('Practice makes perfect!')
5 changes: 5 additions & 0 deletions 03-ControlStructures/zadanie16.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sum = 0
for i in range(1,6):
print(i)
sum = sum + i
print(f'Sum is {sum}')
7 changes: 7 additions & 0 deletions 03-ControlStructures/zadanie17.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sum = 0
i = 1
while i <= 5:
print(i)
sum = sum + i
i = i + 1
print(f'Sum is {sum}')
2 changes: 2 additions & 0 deletions 03-ControlStructures/zadanie18.1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
for i in range(1,11):
print(f'1/{i} = {1/i}')
4 changes: 4 additions & 0 deletions 03-ControlStructures/zadanie18.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
i = 1
while i <= 10:
print(f'1/{i} = {1/i}')
i = i + 1
7 changes: 7 additions & 0 deletions 03-ControlStructures/zadanie19.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sum = 0
i = 1
while i <= 10:
if i%2 == 0:
sum = sum + i
i = i + 1
print (f'Sum is: {sum}')
6 changes: 6 additions & 0 deletions 03-ControlStructures/zadanie21.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a = int(input('Enter first number: '))
b = int(input('Enter second number: '))
if a > b:
print(f'Numbers in ascending order: {b}, {a}')
else:
print(f'Numbers in ascending order: {a}, {b}')
5 changes: 5 additions & 0 deletions 03-ControlStructures/zadanie22.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
a = str(input('Enter name: '))
if a[-1] == 'a':
print(f'{a} - Polish female name')
else:
print('Unknown')
6 changes: 6 additions & 0 deletions 03-ControlStructures/zadanie23.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a = int(input("Enter the dog's age in human years: "))
if a > 2:
print(f"The dog's age in dog’s years is {(2*10.5)+(a-2)*4} years.")
else:
print(f"The dog's age in dog’s years is {a*10.5} years.")

8 changes: 8 additions & 0 deletions 03-ControlStructures/zadanie24.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
a = float(input('Current product price: '))
b = float(input('Previous product price: '))
if a/b <= 0.9:
print("Buy the product!")
print(f"Product price reduced by {round((1-a/b)*100, 2)}%")
else:
print("Don't buy the product!")
print(f"Product price reduced by {round((1-a/b)*100, 2)}%")
6 changes: 6 additions & 0 deletions 03-ControlStructures/zadanie25.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a = int(input('Number of products purchased: '))
b = float(input('Product price: '))
if a > 2:
print(f'Amount to pay: {2*b+(a-2)*(b*0.75)}')
else:
print(f'Amount to pay: {a*b}')
Loading