├── .vscode
└── settings.json
├── LICENSE
├── Midterm
├── Calculator.py
├── Coke.py
├── Heron of Alexandria.py
├── Meteorite.py
├── Netflix.py
├── Palindrome.py
├── Parity.py
└── Volleyball.py
├── Pair_Programming_Online1
├── Sequence I.py
├── Sequence II.py
├── Sequence III.py
├── Sequence IV.py
├── Sequence IX.py
├── Sequence V.py
├── Sequence VI.py
├── Sequence VII.py
├── Sequence VIII.py
└── Sequence X.py
├── Pair_Programming_Online2
├── Align.py
├── ChristmasTree.py
├── FORIE Ball.py
├── FizzBuzz.py
├── Frame.py
├── Future Message.py
├── Grade III.py
├── Hamburger.py
├── Key.py
├── Left Arrow.py
├── Rock Paper Scissor.py
├── Run Length Decoding.py
├── Run Length Encoding.py
├── Sequence N.py
├── Sequence XI.py
├── Sequence XII.py
├── Sneeze.py
├── Table I.py
├── Username.py
└── Virus I.py
├── Pair_Programming_Online3
├── Ball.py
├── Bill.py
├── Blackjack.py
├── Diginity.py
├── Elo.py
├── FourDirections.py
├── Harshad.py
├── Inflation.py
├── Kaprekar.py
├── Lotto.py
├── Milk.py
├── Nearer.py
├── Parallelogram.py
├── ProgressiveTax.py
├── Restaurant.py
├── RightArrow.py
├── RuleofThree.py
├── SecondConverter.py
├── Sequence XXX.py
├── Stair.py
├── Stamps.py
├── Turnstile.py
└── VaildVar.py
├── Pair_Programming_Online4
├── BTSMRT.py
├── B_Fully_pair.py
├── BigFrame.py
├── Books.py
├── Century.py
├── Cha Cha Cha.py
├── MAC.py
├── One For All.py
├── PhoneNumber.py
├── Ping.py
├── Pringles.py
├── Saint Seiya.py
├── Saitama.py
├── Shorten.py
├── Solar System.py
├── Squid Game 3 - Tug-of-War.py
├── diamond.py
└── iPhone 13 Again.py
├── Practice-Final
├── HOW Spike time.py
├── Ranking the scores.py
├── [Onsite-List] Listเลข.py
├── เอาไปใส่ตรงไหนดี.py
└── เอาไปใส่ตรงไหนดีทำไมมันยากจัง.py
├── Practice-Midterm
├── AB Problem.py
├── ABC.py
├── AxB Problem.py
├── BUKA.py
├── Character Checker.py
├── DATUM.py
├── Grading.py
├── Great Common Divisor.py
├── Greatest Common Divisor.py
├── Herman.py
├── Kemija.py
├── Kornislav.py
├── Least Common Multiple.py
├── Matrix Addition.py
├── Min Max.py
├── Modulo.py
├── Okviri.py
├── Pythagorus.py
├── Reseto.py
├── Seven Dwarves.py
├── Skocimis.py
├── Toppykung.py
├── Trik.py
└── X2.py
├── Pre
├── [Pre] AB.py
├── [Pre] Blackjack.py
├── [Pre] Hamburger.py
├── [Pre] Kayak.py
└── [Pre] LeftArrow.py
├── README.md
├── Week11
├── AlmostMean.py
├── AscendingSort.py
├── Backward.py
├── BookWorm.py
├── BusStop I.py
├── Cat Parade.py
├── CuteCat CuteFox.py
├── Diamond I.py
├── Kabata.py
├── LastStand.py
├── LineSorting.py
├── Median.py
├── MissingNumber.py
├── Muddled Menu.py
├── PickThem.py
├── PickThemAgain.py
├── Point Sorting.py
├── RemoveTag.py
├── Runner.py
└── Tuple's Sad life.py
├── Week12
├── All_Primes.py
├── BreachTheDoor.py
├── Calculator V2.py
├── Classify.py
├── CoPrime V1.py
├── Coke V2.py
├── Difference.py
├── Duplicate I.py
├── Filter.py
├── GCD_v1.py
├── HorizontalHistogram.py
├── Impostor.py
├── LetterFrequency.py
├── MissingCard I.py
├── Olympic.py
├── Safe.py
├── Seeker.py
├── WordSequence I.py
├── WordSequence II.py
└── isprime_small.py
├── Week13
├── 3nPlus1.py
├── Amicable.py
├── AndAgainAndAgainAndAgainAndAgainAndAgainAndAgain.py
├── Binary.py
├── CaesarV1.py
├── CaeserV2.py
├── CircularPrime.py
├── ClockHands.py
├── Day2011.py
├── Divide3Or5.py
├── FibonacciRecursionV1.py
├── FibonaciiRecursionV2.py
├── Flatten.py
├── GCD_v2.py
├── Ink.py
├── OneTwo.py
├── PedPonFire.py
├── Perfect.py
├── RectangleArea.py
├── Roman.py
├── SMS.py
├── SceneSwitch I.py
├── SqFree.py
├── VerticalHistogram.py
└── isPrime_large.py
├── Week14
├── Ball.py
├── BiggestIsland.py
├── Bowling-Reddit.py
├── BreakPassword.py
├── CoinChangev1.py
├── Compound Interest.py
├── EuclideanDistance.py
├── GCD_N.py
├── GasStation.py
├── Gram_v1.py
├── HW_DotE.py
├── Island.py
├── MAZE RUNNER.py
├── Matrix_MN.py
├── MultiplyMatrixPQR.py
├── PairNumbering.py
├── Password.py
├── Phasmophobia.py
├── PongYa.py
├── PrasomSib.py
├── Rabbit.py
├── ScaledMatrix.py
├── Scout.py
├── Semi Prime.py
├── ShewaBowlar.py
└── is_prime_LARGER.py
├── Week15
├── Antenna.py
├── BishopMove.py
├── BloodDonation.py
├── BloodType.py
├── Bowling.py
├── Dart.py
├── Difference.py
├── Digit v2.py
├── Discount.py
├── Guess.py
├── Heads and Legs.py
├── ISBN.py
├── Inverter.py
├── Kangaroo.py
├── Kayak.py
├── MasterMind.py
├── NumDays.py
├── OTP.py
├── Perfect City.py
├── Reachability.py
├── Refrigerator.py
├── TicTacToe.py
├── War.py
├── [Recomment] Fever.py
└── [Recomment] Temperature.py
├── Week16
├── ATM.py
├── Area.py
├── Bus Seat.py
├── Colors.py
├── Coupon.py
├── Hamming.py
├── Hint.py
├── IP Address.py
├── Lucky Number.py
├── Majority.py
├── Mickey.py
├── Milk v2.py
├── Pad Thai.py
├── Pro.py
├── Resistor.py
├── RunGame.py
├── Sort.py
├── T-score.py
├── WPM.py
├── [Recomment] Tax.py
└── iPad Air.py
├── Week3
├── Boomerang.py
├── Entryway.py
├── F2C.py
├── FollowTheLead.py
├── Gift I.py
├── JumpAround.py
├── Jumping.py
├── MoreEntryway.py
├── MyMath.py
├── Rectangle.py
├── Regulation.py
├── SaveComputeRepeat.py
├── StillJumping.py
├── Timing.py
└── Train.py
├── Week4
├── BMI.py
├── BMIAgain.py
├── CompositeFunction.py
├── DataSpike.py
├── Distinguish.py
├── EuclideanDistance2D.py
├── FoodGrade I.py
├── Gift II.py
├── Grade I.py
├── Grade II.py
├── ODD_EVEN.py
├── PlanB.py
├── PointInCircle.py
├── Quadrant.py
├── Ratatype.py
├── Robot I.py
├── Seven.py
├── Squareroot.py
├── TheFunctionWithin.py
└── Timing II.py
├── Week5
├── BootSequence.py
├── BrickBridge.py
├── Circular 1.py
├── Circular 2.py
├── Counter.py
├── Day 1.py
├── Donut.py
├── GraderMachince.py
├── HideAndSeek.py
├── HowLong.py
├── LargestNumber.py
├── PlanCDEFGHIJKLMNOPQRSTUVWXYZ.py
├── Repeater.py
├── Runner.py
├── Stepper 1.py
├── Stepper 2.py
├── SumOfNumber.py
├── SurprisingVote.py
├── Triangle 1.py
└── WeightStation.py
├── template.py
└── test.py
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "cSpell.words": [
3 | "icecream",
4 | "kaprekar",
5 | "pringle",
6 | "ขอบคุณที่เราได้พบเจอกัน"
7 | ],
8 | "python.analysis.typeCheckingMode": "basic"
9 | }
--------------------------------------------------------------------------------
/Midterm/Calculator.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | string_builder = ""
5 | value = int(input())
6 | for i in range(value):
7 | if value > 1:
8 | string_builder += str(i + 1)
9 | if i == value - 1:
10 | string_builder += "="
11 | else:
12 | string_builder += "+"
13 | else:
14 | string_builder += "1"
15 | break
16 | print(len(string_builder))
17 | main()
18 |
--------------------------------------------------------------------------------
/Midterm/Coke.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | original_cost = int(input())
5 | promotion_caps_of_coke = int(input())
6 | special_cost = int(input())
7 | amount = int(input())
8 |
9 | price, caps_of_coke = original_cost, 0
10 | currently_balance = 0
11 | while amount > 0:
12 | caps_of_coke += 1
13 | currently_balance += price
14 | price = original_cost #Back to original price
15 | if promotion_caps_of_coke == 0:
16 | currently_balance = original_cost * amount
17 | break
18 | if caps_of_coke == promotion_caps_of_coke:
19 | price = special_cost
20 | caps_of_coke = 0
21 | amount -= 1
22 | print(currently_balance)
23 | main()
24 |
--------------------------------------------------------------------------------
/Midterm/Heron of Alexandria.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def calculate_formula_s(x_value, y_value, z_value):
3 | """Calculate formula s"""
4 | return (x_value + y_value + z_value) / 2
5 |
6 | def main():
7 | """Main function"""
8 | x_value, y_value, z_value = float(input()), float(input()), float(input())
9 | s_value = calculate_formula_s(x_value, y_value, z_value)
10 | area = (s_value*((s_value-x_value)*(s_value-y_value)*(s_value-z_value)))**0.5
11 | print("%.3f" % area)
12 | main()
13 |
--------------------------------------------------------------------------------
/Midterm/Meteorite.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | meteorite = float(input())
5 | more_meteorite = int(input())
6 | safe_of_weight = float(input())
7 | increment, total_missile = 0, 0
8 | if meteorite < safe_of_weight:
9 | total_missile = 0
10 | else:
11 | while not meteorite < safe_of_weight:
12 | meteorite = meteorite / more_meteorite
13 | total_missile += more_meteorite**increment
14 | increment += 1
15 | print(total_missile)
16 | main()
17 |
--------------------------------------------------------------------------------
/Midterm/Netflix.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def display_package(premium, standard, basic, mobile, total):
3 | """Display package functions"""
4 | if premium > 0:
5 | print("Premium x %d" % premium)
6 | if standard > 0:
7 | print("Standard x %d"% standard*(standard > 0))
8 | if basic > 0:
9 | print("Basic x %d" % basic*(basic > 0))
10 | if mobile > 0:
11 | print("Mobile x %d" % mobile*(mobile > 0))
12 | print("Total = %d THB" % total)
13 |
14 | def main():
15 | """Main function"""
16 | number_of_screen = int(input())
17 | number_of_phone = int(input())
18 | input()
19 | input()
20 | watch_tv = input().lower()
21 | hdo = input().lower()
22 | ultra = input().lower()
23 |
24 | counter_premium = 0
25 | counter_standard = 0
26 | counter_basic = 0
27 | counter_mobile = 0
28 | total = 0
29 | while number_of_screen > 0 or number_of_phone > 0:
30 | if (ultra == "yes" or hdo == "yes" or watch_tv == "yes") \
31 | and (number_of_screen >= 3 or number_of_phone >= 3):
32 | total += 419
33 | counter_premium += 1
34 | number_of_screen -= 4
35 | number_of_phone -= 4
36 | elif (hdo == "yes" or watch_tv == "yes") \
37 | and (number_of_screen >= 2 or number_of_phone >= 2):
38 | total += 349
39 | counter_standard += 1
40 | number_of_screen -= 2
41 | number_of_phone -= 2
42 | elif watch_tv == "yes" and ultra == "no" and hdo == "no":
43 | total += 279
44 | counter_basic += 1
45 | number_of_screen -= 1
46 | number_of_phone -= 1
47 | else:
48 | if ultra == "yes":
49 | total += 419
50 | counter_premium += 1
51 | number_of_screen -= 4
52 | number_of_phone -= 4
53 | elif hdo == "yes":
54 | total += 349
55 | counter_standard += 1
56 | number_of_screen -= 2
57 | number_of_phone -= 2
58 | elif watch_tv == "yes":
59 | total += 279
60 | counter_basic += 1
61 | number_of_screen -= 1
62 | number_of_phone -= 1
63 | else:
64 | total += 99
65 | counter_mobile += 1
66 | number_of_screen -= 1
67 | number_of_phone -= 1
68 | display_package(counter_premium, counter_standard, counter_basic, counter_mobile, total)
69 | main()
70 |
--------------------------------------------------------------------------------
/Midterm/Palindrome.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | n_value = int(input())
5 | value = input()
6 | increment = 0
7 | while increment != n_value:
8 | x_value = "%02d" % (int(value[-2:]) + 1)
9 | hours = value[0:2].replace(":", "")
10 | if int(x_value) % 60 == 0 and int(x_value) != 0:
11 | x_value = "00"
12 | y_value = int(hours) + 1
13 | hours = str(y_value)
14 | if int(hours) % 24 == 0:
15 | hours = "0"
16 | value = hours + ":" + x_value
17 | if value.replace(":", "") == value.replace(":", "")[::-1]:
18 | increment = increment + 1
19 | print(value)
20 | main()
21 |
--------------------------------------------------------------------------------
/Midterm/Parity.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | binary = input()
5 | even_or_odd = input().lower()
6 | string_builder = ""
7 | point_increment = 0
8 | for text in binary:
9 | if text == "1":
10 | point_increment += 1
11 | string_builder += text
12 | if even_or_odd == "even":
13 | if point_increment % 2 == 0:
14 | string_builder += str(0)
15 | else:
16 | string_builder += str(1)
17 | if even_or_odd == "odd":
18 | if point_increment % 2 == 0:
19 | string_builder += str(1)
20 | else:
21 | string_builder += str(0)
22 | print(string_builder)
23 | main()
24 |
--------------------------------------------------------------------------------
/Midterm/Volleyball.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def compare_winner(stats_winner_team_a, stats_winner_team_b, value):
3 | """Compare winner function"""
4 | return stats_winner_team_a >= value or stats_winner_team_b >= value
5 |
6 | def is_not_deal_mode(stats_winner_team_a, stats_winner_team_b):
7 | """Check if not deal mode"""
8 | return abs(stats_winner_team_a - stats_winner_team_b) >= 2
9 |
10 | def main():
11 | """Main function"""
12 | value = input() + " "
13 | stats_winner_team_a = 0
14 | stats_winner_team_b = 0
15 | stats_round_team_a = 0
16 | stats_round_team_b = 0
17 | string_builder = ""
18 | increment = 0
19 | finished = False
20 | while len(value) != 0:
21 | for text in value:
22 | if compare_winner(stats_winner_team_a, stats_winner_team_b, 25) \
23 | and is_not_deal_mode(stats_winner_team_a, stats_winner_team_b) and increment <= 3:
24 | finished = True
25 | break
26 | if compare_winner(stats_winner_team_a, stats_winner_team_b, 15) \
27 | and is_not_deal_mode(stats_winner_team_a, stats_winner_team_b) and increment == 4:
28 | finished = True
29 | break
30 | if text == "A":
31 | stats_winner_team_a = stats_winner_team_a + 1
32 | elif text == "B":
33 | stats_winner_team_b = stats_winner_team_b + 1
34 | string_builder = string_builder + text
35 | increment = increment + 1
36 | if stats_winner_team_a > stats_winner_team_b:
37 | stats_round_team_a = stats_round_team_a + 1
38 | else:
39 | stats_round_team_b = stats_round_team_b + 1
40 | if increment <= 5:
41 | print("Set %d: A (%d) | B (%d)"%(increment, stats_winner_team_a, stats_winner_team_b))
42 | value = value.replace(string_builder, "", 1)
43 | if increment >= 4 and finished and stats_round_team_a-stats_round_team_b != 0 \
44 | or (abs(stats_round_team_a-stats_round_team_b) == 3):
45 | print("A won %d:%d set"\
46 | %(stats_round_team_a, stats_round_team_b)*(stats_round_team_a > stats_round_team_b)+\
47 | "B won %d:%d set"\
48 | %(stats_round_team_b, stats_round_team_a)*(stats_round_team_a < stats_round_team_b))
49 | break
50 | #Set to default at all!
51 | finished = False
52 | stats_winner_team_a = 0
53 | stats_winner_team_b = 0
54 | string_builder = ""
55 | if not finished:
56 | print("The game has not finished yet.")
57 | main()
58 |
--------------------------------------------------------------------------------
/Pair_Programming_Online1/Sequence I.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = int(input())
5 | for _ in range(1, value + 1):
6 | for row in range(1, value + 1):
7 | print("%d" % row, end=" ")
8 | print()
9 | main()
10 |
--------------------------------------------------------------------------------
/Pair_Programming_Online1/Sequence II.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = int(input())
5 | total = 0
6 | i = 1
7 | while i <= value:
8 | total += (i * 2 - 1)
9 | print(total, end=" ")
10 | i = i + 1
11 | main()
12 |
--------------------------------------------------------------------------------
/Pair_Programming_Online1/Sequence III.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = int(input())
5 | for line in range(0, value):
6 | for row in range(value):
7 | print(2 + line + row, end=" ")
8 | print()
9 | main()
10 |
--------------------------------------------------------------------------------
/Pair_Programming_Online1/Sequence IV.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = int(input())
5 | attempted = value
6 | col = 0
7 | for _ in range(0, value):
8 | for i in range(col, value):
9 | print(i + 1, end=" ")
10 | col = i + 1
11 | value = value + attempted
12 | print("")
13 | main()
14 |
--------------------------------------------------------------------------------
/Pair_Programming_Online1/Sequence IX.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = int(input())
5 | for i in range(1, value+1):
6 | for j in range(-value+1, value, 1):
7 | if j == 0 or abs(j) < i:
8 | print("%02d" % (i-abs(j)), end=" ")
9 | else:
10 | print(" ", end=" ")
11 | print()
12 | main()
13 |
--------------------------------------------------------------------------------
/Pair_Programming_Online1/Sequence V.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import math
3 | def main():
4 | """Main function"""
5 | x_val = int(input())
6 | y_val = math.ceil(x_val/7)
7 | for _ in range(y_val):
8 | for _ in range(7):
9 | if x_val < 1:
10 | break
11 | print(x_val, end=" ")
12 | x_val -= 1
13 | print()
14 | main()
15 |
--------------------------------------------------------------------------------
/Pair_Programming_Online1/Sequence VI.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | row = int(input())
5 | for i in range(1, row + 1):
6 | for j in range(1, i + 1):
7 | print(j, end=" ")
8 | print()
9 | main()
10 |
--------------------------------------------------------------------------------
/Pair_Programming_Online1/Sequence VII.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = int(input())
5 | for line in range(1, value+1):
6 | for row in range(line):
7 | print(row+1, end=" ")
8 | print()
9 | for line in range(value-1, 0, -1):
10 | for row in range(line):
11 | print(row+1, end=" ")
12 | print()
13 | main()
14 |
--------------------------------------------------------------------------------
/Pair_Programming_Online1/Sequence VIII.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = int(input())
5 | for line in range(1, value+1):
6 | for _ in range(value-line):
7 | print(" ", end=" ")
8 | for row in range(1, line + 1):
9 | print("%02d" %row, end=" ")
10 | print()
11 | main()
12 |
--------------------------------------------------------------------------------
/Pair_Programming_Online1/Sequence X.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = int(input())
5 | for row in range(-(value-1), value):
6 | for col in range(-(value-1), value):
7 | if value - abs(row) >= abs(col) +1:
8 | print("%02d" % (value-abs(col) -abs(row)), end=" ")
9 | else:
10 | print(" ", end=" ")
11 | print()
12 | main()
13 |
--------------------------------------------------------------------------------
/Pair_Programming_Online2/Align.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import math
3 |
4 | def calculate_length(value, length):
5 | """Calculate length"""
6 | return length-len(value)
7 |
8 | def main():
9 | """Main function"""
10 | length = int(input())
11 | side = input()
12 | value = input()
13 | if side == "left":
14 | print(value + " "*calculate_length(value, length))
15 | elif side == "center":
16 | left_side = math.ceil(calculate_length(value, length)/2)
17 | right_side = math.floor(calculate_length(value, length)/2)
18 | print(" "*left_side + value + " "*right_side)
19 | elif side == "right":
20 | print(" "*calculate_length(value, length) + value)
21 | main()
22 |
--------------------------------------------------------------------------------
/Pair_Programming_Online2/ChristmasTree.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = int(input())
5 | row = int(input())
6 | for i in range(1, value + 1):
7 | print(" "*(value-i), end="")
8 | print("*"*(i*2-1))
9 | for _ in range(row):
10 | print(" "*(value-2), end="")
11 | print("---")
12 | main()
13 |
--------------------------------------------------------------------------------
/Pair_Programming_Online2/FORIE Ball.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = input()
5 | result = 1
6 | for string in value:
7 | if string == "A":
8 | if result == 2:
9 | result = 1
10 | elif result == 1:
11 | result = 2
12 | elif string == "B":
13 | if result == 3:
14 | result = 2
15 | elif result == 2:
16 | result = 3
17 | elif string == "C":
18 | if result == 1:
19 | result = 3
20 | elif result == 3:
21 | result = 1
22 | print(result)
23 | main()
24 |
--------------------------------------------------------------------------------
/Pair_Programming_Online2/FizzBuzz.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | count = int(input())
5 | for i in range(1, count + 1):
6 | if i % 3 == 0 and i % 5 == 0:
7 | print("FizzBuzz")
8 | elif i % 3 == 0:
9 | print("Fizz")
10 | elif i % 5 == 0:
11 | print("Buzz")
12 | else:
13 | print(i)
14 | main()
15 |
--------------------------------------------------------------------------------
/Pair_Programming_Online2/Frame.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = input()
5 | print("*" + "*"*len(value) + "*")
6 | print("*" + value + "*")
7 | print("*" + "*"*len(value) + "*")
8 | main()
9 |
--------------------------------------------------------------------------------
/Pair_Programming_Online2/Future Message.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = input()
5 | if value.isnumeric():
6 | print("Number")
7 | elif value.isupper():
8 | print("Uppercase")
9 | elif value.islower():
10 | print("Lowercase")
11 | elif value.istitle():
12 | print("Title")
13 | elif value.isspace():
14 | print("Space")
15 | else:
16 | print("Other")
17 | main()
18 |
--------------------------------------------------------------------------------
/Pair_Programming_Online2/Grade III.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def convert_to_grader(score):
3 | """Convert to grader"""
4 | value = 0
5 | if score >= 95 and score <= 100:
6 | value = 4
7 | elif score >= 90 and score < 95:
8 | value = 3.5
9 | elif score >= 85 and score < 90:
10 | value = 3
11 | elif score >= 80 and score < 85:
12 | value = 2.5
13 | elif score >= 75 and score < 80:
14 | value = 2
15 | elif score >= 70 and score < 75:
16 | value = 1.5
17 | elif score >= 65 and score < 70:
18 | value = 1
19 | elif score >= 60 and score < 65:
20 | value = 0.5
21 | elif score > 0 and score < 60:
22 | value = 0
23 | return value
24 |
25 | def main():
26 | """Main function"""
27 | count = int(input())
28 | score_total = 0
29 | for _ in range(count):
30 | score_total += convert_to_grader(float(input()))
31 | print("%.2f" % ((int((score_total/count)*100))/100))
32 | main()
33 |
--------------------------------------------------------------------------------
/Pair_Programming_Online2/Hamburger.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value_left = int(input())
5 | value_right = int(input())
6 |
7 | left_hamburger = "|"*value_left
8 | right_hamburger = "|"*value_right
9 |
10 | meat = "*"*(value_left*2 + value_right*2)
11 | print(left_hamburger + meat + right_hamburger)
12 | main()
13 |
--------------------------------------------------------------------------------
/Pair_Programming_Online2/Key.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = input()
5 | first = 0
6 | for i in value:
7 | first += int(i)
8 | seconds = int(value[-3:])*10
9 | total = first + seconds
10 | if total < 1000:
11 | total += 1000
12 | print(str(total)[-4:])
13 | main()
14 |
--------------------------------------------------------------------------------
/Pair_Programming_Online2/Left Arrow.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value_x = int(input())
5 | value_y = int(input())
6 | height = int((value_y-1)/2)
7 | final_height = height
8 | for _ in range(0, height+1):
9 | print((" ")*height+("*")*value_x)
10 | height -= 1
11 | for _ in range(0, final_height+1):
12 | height += 1
13 | if height >= 1:
14 | print((" ")*height+("*")*value_x)
15 | main()
16 |
--------------------------------------------------------------------------------
/Pair_Programming_Online2/Rock Paper Scissor.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def game_play(value, a_point, b_point):
3 | """"Game_play function"""
4 | if value[:1] == 'R':
5 | if value[1:] == 'P':
6 | b_point += 1
7 | else:
8 | a_point += 1
9 | if value[:1] == 'S':
10 | if value[1:] == 'P':
11 | a_point += 1
12 | else:
13 | b_point += 1
14 | if value[:1] == 'P':
15 | if value[1:] == 'R':
16 | a_point += 1
17 | else:
18 | b_point += 1
19 | return a_point, b_point
20 |
21 | def main():
22 | """Main function"""
23 | value = str(input())
24 | x_val = ''
25 | y_val = []
26 | player_a_point = 0
27 | player_b_point = 0
28 |
29 | for z_val in value:
30 | if len(x_val) == 1:
31 | if x_val == z_val:
32 | x_val = ''
33 | continue
34 | x_val += z_val
35 | y_val.append(x_val)
36 | x_val = ''
37 | else:
38 | x_val += z_val
39 | for count in range(len(y_val)):
40 | player_a_point, player_b_point = game_play(y_val[count], player_a_point, player_b_point)
41 | if player_a_point == player_b_point:
42 | print("DRAW %d" %(player_a_point))
43 | elif player_a_point > player_b_point:
44 | print("A win %d-%d" %(player_a_point, player_b_point))
45 | elif player_b_point > player_a_point:
46 | print("B win %d-%d" %(player_b_point, player_a_point))
47 | main()
48 |
--------------------------------------------------------------------------------
/Pair_Programming_Online2/Run Length Decoding.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | x_val = str(input())
5 | y_val = ""
6 | for string in x_val:
7 | if string.isnumeric():
8 | y_val += string
9 | else:
10 | print(string * int(y_val), end="")
11 | y_val = ""
12 | main()
13 |
--------------------------------------------------------------------------------
/Pair_Programming_Online2/Run Length Encoding.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = input()
5 | checker = value[0]
6 | count = 0
7 | x_val = ""
8 | for i in range(0, len(value)):
9 | if checker == value[i]:
10 | count += 1
11 | else:
12 | x_val += str(count) + value[i-1]
13 | checker = value[i]
14 | count = 1
15 | x_val += str(count) + value[-1]
16 | print(x_val)
17 |
18 | main()
19 |
--------------------------------------------------------------------------------
/Pair_Programming_Online2/Sequence N.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = int(input())
5 | for i in range(value):
6 | for j in range(value):
7 | if i == j or j == value - 1 or j == 0:
8 | print("*", end="")
9 | else:
10 | print("", end=" ")
11 | print()
12 | main()
13 |
--------------------------------------------------------------------------------
/Pair_Programming_Online2/Sequence XI.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = int(input())
5 | for i in range(-value + 1, value, 1):
6 | for j in range(-value + 1, value, 1):
7 | if abs(i) > abs(j) - 1:
8 | print("%02d"%(value - abs(i)), end=" ")
9 | else:
10 | print("%02d"%(value - abs(j)), end=" ")
11 | print()
12 | main()
13 |
--------------------------------------------------------------------------------
/Pair_Programming_Online2/Sequence XII.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = int(input())
5 | for i in range(-value + 1, value):
6 | for j in range(-value + 1, value):
7 | print("%02d"%(value - abs(abs(i) - abs(j))), end=" ")
8 | print()
9 | main()
10 |
--------------------------------------------------------------------------------
/Pair_Programming_Online2/Sneeze.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = input()
5 | print(value.swapcase())
6 | main()
7 |
--------------------------------------------------------------------------------
/Pair_Programming_Online2/Table I.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | multiply = int(input())
5 | for i in range(1, multiply + 1):
6 | print("15 x %d = %d" % (i, 15*i))
7 | main()
8 |
--------------------------------------------------------------------------------
/Pair_Programming_Online2/Username.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = input()
5 | print(value.lower())
6 | main()
7 |
--------------------------------------------------------------------------------
/Pair_Programming_Online2/Virus I.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = input()
5 | total = 0
6 | for character in value:
7 | if character == "o":
8 | total += 1
9 | print(total)
10 | main()
11 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/Ball.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | height = float(input())
5 | count = -1
6 | while height >= 0.01:
7 | height = height * 3 / 5
8 | count += 1
9 | print(count)
10 | main()
11 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/Bill.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | price = int(input())
5 |
6 | value = price * 10 / 100
7 | #value is less 50, set value to 50
8 | if value < 50:
9 | value = 50
10 | #Than value is most 1000, set value to 1000
11 | if value > 1000:
12 | value = 1000
13 |
14 | #Let's process it, I don't care grammar because my english so bad ;-;
15 | total = price + value
16 | total = total * 107 / 100
17 | print("%.2f" % total)
18 | main()
19 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/Blackjack.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | x_val = []
5 | y_val = []
6 | amount = int(input())
7 | for _ in range(amount):
8 | card = input()
9 | if card in "jkqJKQ":
10 | card = 10
11 | x_val.append(card)
12 | elif card in "Aa":
13 | y_val.append("A")
14 | else: # number
15 | x_val.append(int(card))
16 | while len(y_val) > 0:
17 | y_val.remove("A")
18 | if sum(x_val) + 11 > 21:
19 | x_val.append(1)
20 | elif sum(x_val) == 10 and len(y_val) == 1:
21 | x_val.append(1)
22 | else:
23 | x_val.append(11)
24 | print(sum(x_val))
25 | main()
26 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/Diginity.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def recessive_loop(x_val):
3 | """Recessive loop"""
4 | value = 0
5 | for i in x_val:
6 | value += int(i)
7 | if len(str(value)) != 1:
8 | value = recessive_loop(str(value))
9 | return value
10 |
11 | def main():
12 | """Main function"""
13 | while True:
14 | x_val = input()
15 | value = 0
16 | if x_val == "0":
17 | break
18 | else:
19 | value = recessive_loop(x_val)
20 | print(value)
21 | main()
22 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/Elo.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | x_val = int(input())
5 | y_val = int(input())
6 | type_player = input()
7 | if type_player == "A":
8 | elo = 1/(1+(10**((y_val-x_val)/400)))
9 | elif type_player == "B":
10 | elo = 1/(1+(10**((x_val-y_val)/400)))
11 | print("%.2f" %elo)
12 | main()
13 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/FourDirections.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | text = input()
5 | line1 = ""
6 | line2 = ""
7 | line3 = ""
8 | line4 = ""
9 | line5 = ""
10 | for i in text:
11 | if i == "U":
12 | line1 += " * "
13 | line2 += " *** "
14 | line3 += "* * * "
15 | line4 += " * "
16 | line5 += " * "
17 | elif i == "D":
18 | line1 += " * "
19 | line2 += " * "
20 | line3 += "* * * "
21 | line4 += " *** "
22 | line5 += " * "
23 | elif i == "L":
24 | line1 += " * "
25 | line2 += " * "
26 | line3 += "***** "
27 | line4 += " * "
28 | line5 += " * "
29 | elif i == "R":
30 | line1 += " * "
31 | line2 += " * "
32 | line3 += "***** "
33 | line4 += " * "
34 | line5 += " * "
35 | print(line1)
36 | print(line2)
37 | print(line3)
38 | print(line4)
39 | print(line5)
40 |
41 | main()
42 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/Harshad.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def digit_sum(x_val):
3 | """Sum of digits"""
4 | value = 0
5 | x_val = str(x_val)
6 | if int(x_val) < 0:
7 | for i in x_val[1:]:
8 | value = value + int(i)
9 | value = value * (-1)
10 | else:
11 | for i in x_val:
12 | value = value + int(i)
13 | return value
14 |
15 | def main():
16 | """Main function"""
17 | for _ in range(10):
18 | x_val = int(input())
19 | # If input is 0, then say NO!
20 | if x_val == 0:
21 | print("No")
22 | elif len(str(x_val)) == 1:
23 | # If input is same input, then say YES!
24 | if x_val % x_val == 0:
25 | print("Yes")
26 | else:
27 | print("No")
28 | else:
29 | # Process the input
30 | if x_val % digit_sum(x_val) == 0:
31 | print("Yes")
32 | else:
33 | print("No")
34 | main()
35 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/Inflation.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | cost = float(input())
5 | years = int(input())
6 | percent = 381
7 | cost = int(cost * 100)
8 | for _ in range(years):
9 | interest = cost * percent
10 | cost = cost + interest // 10000
11 | value_1 = str(cost)
12 | value_2 = value_1[-2::]
13 | value_3 = value_1[::-1]
14 | value_3 = value_3[2::]
15 | value_3 = value_3[::-1]
16 | if value_3 == "":
17 | value_3 = "0"
18 | if value_2 == "":
19 | value_2 = "0"
20 |
21 | print("%d.%02d" % (int(value_3), int(value_2)))
22 | main()
23 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/Kaprekar.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def calculate_kaprekar(number):
3 | """Calculate kaprekar"""
4 | x_val = []
5 | for i in number:
6 | x_val.append(int(i))
7 | value = []
8 | calculate = ""
9 | while x_val:
10 | sk_upper = x_val[0]
11 | for i in x_val:
12 | if i < sk_upper:
13 | sk_upper = i
14 | value.append(sk_upper)
15 | x_val.remove(sk_upper)
16 | for i in value:
17 | calculate += str(i)
18 | return calculate
19 |
20 | def main():
21 | """Main function"""
22 | value = input()
23 | count = 1
24 | while value != "6174":
25 | if value == "6174":
26 | print(count)
27 | break
28 | if len(str(value)) < 4:
29 | value = value + "0"
30 | else:
31 | sk_number_value = calculate_kaprekar(value)[::-1]
32 | number = int(sk_number_value) - int(sk_number_value[::-1])
33 | if number == 6174:
34 | print(count)
35 | break
36 | else:
37 | value = str(number)
38 | count = count + 1
39 |
40 | main()
41 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/Lotto.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | first_prize = input()
5 | last_two_digit_prize = input()
6 | front_three_digit_first_prize = input()
7 | front_three_digit_second_prize = input()
8 | last_three_digit_first_prize = input()
9 | last_three_digit_second_prize = input()
10 | lotto = input()
11 | balance = 0
12 |
13 | #First Prize!
14 | if lotto == first_prize:
15 | balance += 6000000
16 |
17 | #You so lucky! Last two digit is the same!
18 | if lotto[-2] == last_two_digit_prize[0] and \
19 | lotto[-1] == last_two_digit_prize[1]:
20 | balance += 2000
21 |
22 | #You so lucky! Front three digit is the same!
23 | if lotto[0] == front_three_digit_first_prize[0] \
24 | and lotto[1] == front_three_digit_first_prize[1]\
25 | and lotto[2] == front_three_digit_first_prize[2]:
26 | balance += 4000
27 | if lotto[0] == front_three_digit_second_prize[0] \
28 | and lotto[1] == front_three_digit_second_prize[1]\
29 | and lotto[2] == front_three_digit_second_prize[2]:
30 | balance += 4000
31 |
32 | #You so lucky! Last three digit is the same!
33 | if lotto[-1] == last_three_digit_first_prize[2] and \
34 | lotto[-2] == last_three_digit_first_prize[1] and \
35 | lotto[-3] == last_three_digit_first_prize[0]:
36 | balance += 4000
37 | if lotto[-1] == last_three_digit_second_prize[2] and \
38 | lotto[-2] == last_three_digit_second_prize[1] and \
39 | lotto[-3] == last_three_digit_second_prize[0]:
40 | balance += 4000
41 |
42 | #Similar prize
43 | if int(first_prize) == 0 and (int(lotto) == 999999 or int(lotto) == 1):
44 | balance += 100000
45 | elif int(first_prize) == 999999 and (int(lotto) == 0 or int(lotto) == 999998):
46 | balance += 100000
47 | elif (int(lotto)) == int(first_prize)+1 or (int(lotto)) == int(first_prize)-1:
48 | balance += 100000
49 |
50 | print(balance)
51 | main()
52 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/Milk.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | a_val = int(input())
5 | b_val = int(input())
6 | c_val = int(input())
7 | d_val = int(input())
8 | cap = d_val // a_val
9 | milk = cap
10 | if b_val == 0:
11 | print(milk)
12 | else:
13 | while True:
14 | more = (cap // b_val) * c_val
15 | milk += more
16 | mod = (cap % b_val)
17 | cap = 0
18 | cap += mod
19 | cap += more
20 | more = 0
21 | if cap < b_val:
22 | break
23 | print(milk)
24 | main()
25 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/Nearer.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | distance_alice = int(input())
5 | distance_bob = int(input())
6 | distance_icecream = int(input())
7 | distance_alice_to_icecream = abs(distance_icecream - distance_alice) # abs() is absolute value
8 | distance_bob_to_icecream = abs(distance_icecream - distance_bob)
9 | if distance_alice_to_icecream < distance_bob_to_icecream:
10 | print("Alice %d" % distance_alice_to_icecream)
11 | elif distance_alice_to_icecream > distance_bob_to_icecream:
12 | print("Bob %d" % distance_bob_to_icecream)
13 | else:
14 | print("Sundaes %d" % distance_alice_to_icecream)
15 | main()
16 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/Parallelogram.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | text = input()
5 | count = len(text)
6 | for i in range(0, count + 1):
7 | if i == 0:
8 | continue
9 | elif i != count:
10 | print(" ", end="")
11 | print(" "*(count-i-1)+text[0:i:+1])
12 | for i in range(0, count + 1):
13 | if text[i+1:count:] == "":
14 | continue
15 | print(""+text[i+1:count:]+"")
16 | main()
17 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/ProgressiveTax.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | salary = int(input())
5 | tax = 0
6 | if salary > 4000000:
7 | calc_salary = salary - 4000000
8 | salary -= calc_salary
9 | tax += calc_salary * 0.35
10 | if salary > 2000000:
11 | calc_salary = salary - 2000000
12 | salary -= calc_salary
13 | tax += calc_salary * 0.30
14 | if salary > 1000000:
15 | calc_salary = salary - 1000000
16 | salary -= calc_salary
17 | tax += calc_salary * 0.25
18 | if salary > 750000:
19 | calc_salary = salary - 750000
20 | salary -= calc_salary
21 | tax += calc_salary * 0.20
22 | if salary > 500000:
23 | calc_salary = salary - 500000
24 | salary -= calc_salary
25 | tax += calc_salary * 0.15
26 | if salary > 300000:
27 | calc_salary = salary - 300000
28 | salary -= calc_salary
29 | tax += calc_salary * 0.10
30 | if salary > 150000:
31 | calc_salary = salary - 150000
32 | salary -= calc_salary
33 | tax += calc_salary * 0.05
34 | if salary > 0:
35 | pass
36 | print(int(tax))
37 | main()
38 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/Restaurant.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | order_food = float(input())
5 | promotion = float(input())
6 | discount = float(input())
7 | x_val = float(input())
8 | total = order_food + x_val
9 | if total >= promotion:
10 | total -= total*(discount/100)
11 | if order_food >= promotion:
12 | order_food -= order_food*(discount/100)
13 | if total > order_food:
14 | print("No %.03f" %(total - order_food))
15 | elif total < order_food:
16 | print("Yes %.03f" %(order_food - total))
17 | else:
18 | print("Yes")
19 | main()
20 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/RightArrow.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | light_width = int(input())
5 | light_height = int(input())
6 |
7 | gap = int((light_height - 1) / 2)
8 | for i in range(gap, 0, -1):
9 | print(' '*(gap - i) + '*'*light_width)
10 | print(' ' * gap + '*' * light_width)
11 | for i in range(gap):
12 | print(' '*(gap - i - 1) + '*'*light_width)
13 | main()
14 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/RuleofThree.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def insert_into_list(x_val, price, weight, is_clear=False):
3 | """Insert into list Function"""
4 | if is_clear:
5 | x_val.clear()
6 | x_val.append(price)
7 | x_val.append(weight)
8 |
9 | def main():
10 | """Main function"""
11 | value = int(input())
12 | x_val = []
13 | counter = 0
14 | for _ in range(value):
15 | price = float(input())
16 | weight = float(input())
17 | if x_val == []:
18 | insert_into_list(x_val, price, weight)
19 | counter = weight/price
20 | if counter > weight/price and counter != 0:
21 | continue
22 | elif counter < weight/price and counter != 0:
23 | counter = weight/price
24 | insert_into_list(x_val, price, weight, True)
25 | elif counter == weight/price and counter != 0:
26 | if x_val[0] > price:
27 | insert_into_list(x_val, price, weight, True)
28 | print("%.2f %.2f"%(x_val[0], x_val[1]))
29 | main()
30 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/SecondConverter.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | custom_time = int(input())
5 | seconds_in_seconds = int(input())
6 | mins_in_seconds = int(input())
7 | hours_in_seconds = int(input())
8 |
9 | mins = custom_time // seconds_in_seconds
10 | seconds = custom_time % seconds_in_seconds
11 | hours = mins // mins_in_seconds
12 | mins = mins % mins_in_seconds
13 | hours = hours % hours_in_seconds
14 | print("%d:%d:%d" % (hours, mins, seconds))
15 | main()
16 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/Sequence XXX.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | size = int(input())
5 | unit = int(input())
6 | for i in range(size):
7 | if i == 0 or i == size-1:
8 | for _ in range(unit):
9 | print("*" * size, end=" ")
10 | print()
11 | else:
12 | for _ in range(unit):
13 | for j in range(size):
14 | if i == j or j == 0 or j == size-1 or j == size-1-i:
15 | print("*", end="")
16 | else:
17 | print(" ", end="")
18 | print("", end=" ")
19 | print()
20 | main()
21 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/Stair.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | cat_is_bug = True
5 | checker = 0
6 | countable_integer = 0
7 |
8 | highest = int(input())
9 | floor = int(input())
10 | for _ in range(1, floor + 1):
11 | jumping = int(input())
12 | checker = checker + jumping
13 | if jumping > highest:
14 | cat_is_bug = False
15 | elif checker == highest:
16 | countable_integer = countable_integer + 1
17 | checker = 0
18 | elif checker > highest:
19 | countable_integer = countable_integer + 1
20 | checker = jumping
21 | if checker > 0:
22 | countable_integer = countable_integer + 1
23 | if cat_is_bug:
24 | print("%d" % countable_integer)
25 | else:
26 | print("NO")
27 |
28 | main()
29 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/Stamps.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | length_val = int(input())
5 | a_val = int(input())
6 | b_val = int(input())
7 | c_val = int(input())
8 | d_val = int(input())
9 | stamp = 0
10 | total = 0
11 | for _ in range(length_val):
12 | amount = int(input())
13 | discount = amount
14 | while True:
15 | if stamp >= c_val and discount > 0:
16 | stamp -= c_val
17 | discount -= d_val
18 | else:
19 | break
20 | if amount >= a_val:
21 | if b_val != 0 or d_val != 0:
22 | stamp += int((discount / a_val)) * b_val
23 | if discount <= 0:
24 | total += 0
25 | else:
26 | total += discount
27 | print("%d" % total)
28 | print("%d" % stamp)
29 | main()
30 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/Turnstile.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | kick_in_the_door_waving_co_co = 0
5 | people = 0
6 | while True:
7 | action = input().lower()
8 | if action == "end":
9 | break
10 | if action == "c":
11 | kick_in_the_door_waving_co_co = 1
12 | if action == "p":
13 | if kick_in_the_door_waving_co_co == 1:
14 | people = people + 1
15 | kick_in_the_door_waving_co_co = 0
16 | print(people)
17 | main()
18 |
--------------------------------------------------------------------------------
/Pair_Programming_Online3/VaildVar.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def true_or_false(x_val):
3 | """True or False"""
4 | if x_val == "True" or x_val == "False":
5 | return True
6 | return False
7 |
8 | def checker_one(x_val):
9 | """Check one"""
10 | if x_val == "None" or x_val == "and" or x_val == "as" or x_val == "assert":
11 | return True
12 | if x_val == "async" or x_val == "await" or x_val == "break" or x_val == "class":
13 | return True
14 | return False
15 |
16 |
17 | def checker_two(x_val):
18 | """Check one"""
19 | if x_val == "continue" or x_val == "def" or x_val == "del" or x_val == "elif":
20 | return True
21 | if x_val == "else" or x_val == "except" or x_val == "finally" or x_val == "for":
22 | return True
23 | return False
24 |
25 | def checker_three(x_val):
26 | """Check one"""
27 | if x_val == "from" or x_val == "global" or x_val == "if" or x_val == "import":
28 | return True
29 | if x_val == "in" or x_val == "is" or x_val == "lambda" or x_val == "nonlocal":
30 | return True
31 | return False
32 |
33 |
34 | def checker_four(x_val):
35 | """Check one"""
36 | if x_val == "not" or x_val == "or" or x_val == "pass" or x_val == "raise":
37 | return True
38 | if x_val == "return" or x_val == "try" or x_val == "while" or x_val == "with":
39 | return True
40 | if x_val == "yield":
41 | return True
42 | return False
43 |
44 | def checker_valuable(var):
45 | """Checker valuable"""
46 | if true_or_false(var) or checker_one(var) or checker_two(var) or checker_three(var) \
47 | or checker_four(var):
48 | return True
49 | return False
50 |
51 | def main():
52 | """Main function"""
53 | count = int(input())
54 | pattern = '''!()-[];:'",<>./?\\@#$%^+=&*~'''
55 | checker = ""
56 | for _ in range(count):
57 | valuable = input()
58 | if valuable[-1] == " ":
59 | #Check last index string
60 | valuable = valuable[:-1]
61 | for y_val in valuable:
62 | if y_val in pattern or checker_valuable(valuable) or valuable[0].isdigit() \
63 | or " " in valuable[1:]:
64 | print("Invalid")
65 | checker = ""
66 | break
67 | else:
68 | checker = checker + y_val
69 | if valuable == checker:
70 | print("Valid")
71 | checker = ""
72 | break
73 | main()
74 |
--------------------------------------------------------------------------------
/Pair_Programming_Online4/BTSMRT.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | day = input()
5 | age = float(input())
6 | height = float(input())
7 | if day == "Normal Day" and age < 14 and height < 90:
8 | print("FREE")
9 | elif day == "Children Day" and age < 14 and height <= 140 or age < 14 and height < 90:
10 | print("FREE")
11 | elif day == "Senior Day" and age >= 60 or age < 14 and height < 90:
12 | print("FREE")
13 | else:
14 | print("PAY")
15 | main()
16 |
--------------------------------------------------------------------------------
/Pair_Programming_Online4/B_Fully_pair.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = input().lower()
5 | test = ''
6 | result = ''
7 | count = 0
8 | for idx in value:
9 | if test.count(idx) <= 0:
10 | test += idx
11 | for idx in test:
12 | if (int(value.count(idx)) % 2) == 1:
13 | count += 1
14 | result += idx
15 | print('fully paired' if count == 0 else result)
16 | main()
17 |
--------------------------------------------------------------------------------
/Pair_Programming_Online4/BigFrame.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | text_1 = input().rstrip()
5 | text_2 = input().rstrip()
6 | text_3 = input().rstrip()
7 | text_4 = input().rstrip()
8 | text_5 = input().rstrip()
9 | line = max(len(text_1), len(text_2), len(text_3), len(text_4), len(text_5))
10 | print("**" + "*" * line + "**")
11 | print("* " + text_1 + " " * (line - len(text_1)) + " *")
12 | print("* " + text_2 + " " * (line - len(text_2)) + " *")
13 | print("* " + text_3 + " " * (line - len(text_3)) + " *")
14 | print("* " + text_4 + " " * (line - len(text_4)) + " *")
15 | print("* " + text_5 + " " * (line - len(text_5)) + " *")
16 | print("**" + "*" * line + "**")
17 | main()
18 |
--------------------------------------------------------------------------------
/Pair_Programming_Online4/Books.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import math
3 |
4 | def main():
5 | """Main function"""
6 | value_1 = int(input())
7 | value_2 = int(input())
8 | value_3 = int(input())
9 | value_4 = int(input())
10 | count = 0
11 | day = 0
12 | counter = 0
13 | while True:
14 | value_5 = math.ceil((value_3 / value_4) * value_2)
15 | if count == value_1:
16 | break
17 | if value_5 >= value_2:
18 | break
19 | counter += value_5
20 | if counter >= value_2:
21 | counter = 0
22 | count += 1
23 | value_3 += 1
24 | value_4 += 1
25 | day += 1
26 | day += (value_1-count)
27 | print(day)
28 | main()
29 |
--------------------------------------------------------------------------------
/Pair_Programming_Online4/Century.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import math
3 |
4 | def calculate_year(year):
5 | """Calculate year"""
6 | if year < 1:
7 | return 'ERROR'
8 | elif year >= 1 and year <= 100:
9 | return 1
10 | else:
11 | return int(math.ceil(year / 100))
12 |
13 | def main():
14 | """Main function"""
15 | value = int(input())
16 | for _ in range(value):
17 | idx = input()
18 | idx1 = idx[idx.count(". ") + 4 : len(idx)]
19 | year = int(idx1)
20 | if idx.count("B.E.") >= 1:
21 | year -= 543
22 | print(calculate_year(year))
23 | elif idx.count("A.D.") >= 1:
24 | print(calculate_year(year))
25 | main()
26 |
--------------------------------------------------------------------------------
/Pair_Programming_Online4/Cha Cha Cha.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import math
3 |
4 | def main():
5 | """Main function"""
6 | x_val = int(input())
7 | total = 0
8 | for _ in range(x_val):
9 | test = int(math.ceil(float(input())))
10 | total += test * 8720
11 | print(total)
12 | main()
13 |
--------------------------------------------------------------------------------
/Pair_Programming_Online4/MAC.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = input()
5 | if not (len(value) == 17 or len(value) == 14):
6 | return print("ERROR")
7 |
8 | character = "ABCDEFabcdef1234567890.:-"
9 |
10 | for i in value:
11 | if i not in character:
12 | return print("ERROR")
13 | if not (value.count("-") == 5 or value.count(":") == 5 or value.count(".") == 2):
14 | return print("ERROR")
15 | if value[2] == "-" and value[5] == "-" and value[8] == "-"\
16 | and value[11] == "-" and value[14] == "-":
17 | print("VALID 1")
18 | elif value[2] == ":" and value[5] == ":" and value[8] == ":"\
19 | and value[11] == ":" and value[14] == ":":
20 | print("VALID 2")
21 | elif value[4] == "." and value[9] == "." and value[:4].isalnum()\
22 | and value[5:9].isalnum() and value[10:\
23 | ].isalnum():
24 | print("VALID 3")
25 | else:
26 | print("ERROR")
27 | main()
28 |
--------------------------------------------------------------------------------
/Pair_Programming_Online4/One For All.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | counter = int(input())
5 | exp = 0
6 | value = ""
7 | for _ in range(counter):
8 | txt = input()
9 | exp += 1
10 | if exp == counter:
11 | value += (txt + "_%d" % counter)
12 | elif exp % 2 == 0:
13 | value += (txt + "-" * exp)
14 | else:
15 | value += (txt + "*" * exp)
16 | print(value)
17 | main()
18 |
--------------------------------------------------------------------------------
/Pair_Programming_Online4/PhoneNumber.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | phone_number = input()
5 | nation = input()
6 | if len(phone_number) == 9:
7 | if nation == "Domestic":
8 | print(phone_number[0] + " " + phone_number[1:5] + " " +phone_number[5:])
9 | else:
10 | print("+66"+" " + phone_number[1:5] + " " + phone_number[5:])
11 | else:
12 | if nation == "Domestic":
13 | print(phone_number[0:2:] + " " + phone_number[2:6] + " " + phone_number[6:])
14 | else:
15 | print("+66" + phone_number[1] + " " + phone_number[2:6] + " " + phone_number[6:])
16 | main()
17 |
--------------------------------------------------------------------------------
/Pair_Programming_Online4/Pringles.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | border_top = input()
5 | pringle = input()
6 | border_bottom = input()
7 | value = int(input())
8 |
9 | eat_count = 0
10 | left_count = 0
11 | eat = pringle[:value:]
12 | left = pringle[value::]
13 |
14 | for i in eat:
15 | if i == ")":
16 | eat_count = eat_count + 1
17 | for i in left:
18 | if i == ")":
19 | left_count = left_count + 1
20 |
21 | print(eat_count)
22 | if left_count == 0:
23 | print("None.")
24 | else:
25 | print("There are still some left.")
26 |
27 | print(border_top)
28 | print("%s%s" %((" "*value), pringle[value:]))
29 | print(border_bottom)
30 | main()
31 |
--------------------------------------------------------------------------------
/Pair_Programming_Online4/Saint Seiya.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | second = int(input())
5 | push = int(input())
6 |
7 | counter = 0
8 | for i in range(2, second+1, 2):
9 | if counter < push:
10 | if i % 6 == 0:
11 | counter += 1
12 | elif i % 2 == 0:
13 | counter += 165
14 | else:
15 | counter += (second+1-i)*12
16 | break
17 | print(counter)
18 | main()
19 |
--------------------------------------------------------------------------------
/Pair_Programming_Online4/Saitama.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | requirement1, requirement2 = int(input()), int(input())
5 | requirement3, requirement4 = int(input()), int(input())
6 | count1, count2 = int(input()), int(input())
7 | count3, count4 = int(input()), int(input())
8 |
9 | idx1 = requirement1 / count1
10 | idx2 = requirement2 / count2
11 | idx3 = requirement3 / count4
12 | idx4 = requirement4 / count3
13 |
14 | for _ in range(4):
15 | if idx1 <= idx2:
16 | idx1, idx2 = idx2, idx1
17 | if idx2 <= idx3:
18 | idx2, idx3 = idx3, idx2
19 | if idx3 <= idx4:
20 | idx3, idx4 = idx4, idx3
21 | print(int(idx1 + 0.999999999))
22 | main()
23 |
--------------------------------------------------------------------------------
/Pair_Programming_Online4/Shorten.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | idx1 = 0
5 | idx2 = 0
6 | result = ''
7 | while True:
8 | value = int(input())
9 | if value == -1:
10 | if result == '':
11 | result = str(idx1) if idx1 == (idx1 + idx2) \
12 | else str(idx1) + '-' + str(idx1 + idx2)
13 | else:
14 | result = result + ', ' + str(idx1) if idx1 == (idx1 + idx2) else result + \
15 | ', ' + str(idx1) + '-' + str(idx1 + idx2)
16 | break
17 | if idx1 != value:
18 | if idx1 == 0:
19 | idx1 = value
20 | elif (idx1 + idx2 + 1) == value:
21 | idx2 += 1
22 | else:
23 | if result == '':
24 | result = str(idx1) if idx1 == (idx1 + idx2) else str(idx1) + \
25 | '-' + str(idx1 + idx2)
26 | else:
27 | result = result + ', ' + str(idx1) if idx1 == (idx1 + idx2) else result + \
28 | ', ' + str(idx1) + '-' + str(idx1 + idx2)
29 | idx1 = value
30 | idx2 = 0
31 | print('' if result == '0' else result)
32 | main()
33 |
--------------------------------------------------------------------------------
/Pair_Programming_Online4/Solar System.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def find_index_planet_sun(x_val, index):
3 | """Find index of planet in sun"""
4 | for i in range(x_val.count(" ")):
5 | value = x_val[0:x_val.find(" ")]
6 | if index == i:
7 | return value
8 | x_val = x_val[x_val.find(" ")+1:]
9 |
10 | def calculate_finding_a_planet_hot_and_cool(x_val, count_of_x_val, index):
11 | """Calculate finding a planet hot and cool"""
12 | planet_hot = ''
13 | planet_cool = ''
14 | planet_hot = str(find_index_planet_sun(x_val, index - 1))
15 | if count_of_x_val >= 3:
16 | planet_cool = str(find_index_planet_sun(x_val, 0))
17 | elif count_of_x_val == 2:
18 | planet_cool = str(find_index_planet_sun(x_val, index - 1))
19 | return planet_hot, planet_cool
20 |
21 | def main():
22 | """Main function"""
23 | value = str(input())
24 | index = -1
25 | planet_hot = ""
26 | planet_cool = ""
27 |
28 | x_val = value
29 | count_of_value = value.count(" ")
30 | for i in range(count_of_value):
31 | y_val = x_val[0:x_val.find(" ")]
32 | if y_val.lower() == "sun":
33 | index = i
34 | x_val = x_val[x_val.find(" ")+1:]
35 | if index == -1:
36 | #If the sun is not in the list of planets
37 | pass
38 |
39 | elif index == 0:
40 | planet_hot = str(find_index_planet_sun(value, index + 1))
41 | if count_of_value >= 3:
42 | planet_cool = str(find_index_planet_sun(value, count_of_value - 1))
43 | elif count_of_value == 2:
44 | planet_cool = str(find_index_planet_sun(value, index + 1))
45 | elif index == count_of_value or index == count_of_value - 1:
46 | planet_hot, planet_cool = calculate_finding_a_planet_hot_and_cool(value, count_of_value, index)
47 | else:
48 | if count_of_value > 3:
49 | planet_hot = str(find_index_planet_sun(value, index - 1)) + " " + str(find_index_planet_sun(value, index + 1))
50 | if count_of_value >= 5 and int(count_of_value / 2) == index:
51 | planet_cool = str(find_index_planet_sun(value, 0)) + " " + str(find_index_planet_sun(value, count_of_value - 1))
52 | else:
53 | if index == 1 or int(count_of_value / 2) > index:
54 | planet_cool = str(find_index_planet_sun(value, count_of_value - 1))
55 | elif index == count_of_value - 2 or int(count_of_value / 2) < index:
56 | planet_cool = str(find_index_planet_sun(value, 0))
57 | else:
58 | planet_hot = str(find_index_planet_sun(value, index - 1)) + " " + str(find_index_planet_sun(value, index + 1))
59 | planet_cool = str(find_index_planet_sun(value, index - 1)) + " " + str(find_index_planet_sun(value, index + 1))
60 |
61 | #Solution of the problem
62 | print('Hot: ' + planet_hot)
63 | print('Cool: ' + planet_cool)
64 | main()
--------------------------------------------------------------------------------
/Pair_Programming_Online4/Squid Game 3 - Tug-of-War.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | team_a = 0
5 | team_b = 0
6 | for _ in range(10):
7 | team_a += int(input())
8 | for _ in range(10):
9 | team_b += int(input())
10 | if team_a == team_b:
11 | print('AB')
12 | elif team_a > team_b:
13 | print('B')
14 | elif team_a < team_b:
15 | print('A')
16 | main()
17 |
--------------------------------------------------------------------------------
/Pair_Programming_Online4/diamond.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = int(input())
5 | half = value //2
6 | for i in range(value):
7 | for j in range(value):
8 | if i == half or i + j == half or j - i == half or i - j == half or\
9 | j == value - i + half - 1:
10 | print("*", end="")
11 | else:
12 | print(" ", end="")
13 | print()
14 | main()
15 |
--------------------------------------------------------------------------------
/Pair_Programming_Online4/iPhone 13 Again.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def check_disk(name, disk):
3 | """main"""
4 | if disk == "128 GB":
5 | return 0
6 | elif disk == "256 GB":
7 | return 4000
8 | elif disk == "512 GB":
9 | return 12000
10 | elif disk == "1 TB":
11 | if name == "iPhone 13 mini" or name == "iPhone 13":
12 | return -1
13 | else:
14 | return 20000
15 | else:
16 | return -1
17 |
18 | def main():
19 | """Main function"""
20 | idx1 = input()
21 | disk = input()
22 | disk = check_disk(idx1, disk)
23 | if disk == -1:
24 | print('Not Available')
25 | else:
26 | if idx1 == "iPhone 13 mini":
27 | print(25900 + disk)
28 | elif idx1 == "iPhone 13":
29 | print(29900 + disk)
30 | elif idx1 == "iPhone 13 Pro":
31 | print(38900 + disk)
32 | elif idx1 == "iPhone 13 Pro Max":
33 | print(42900 + disk)
34 | else:
35 | print('Not Available')
36 | main()
37 |
--------------------------------------------------------------------------------
/Practice-Final/HOW Spike time.py:
--------------------------------------------------------------------------------
1 | """Thank you ขอบคุณที่เราได้พบเจอกัน"""
2 | def f_function(value):
3 | return (2 + (3**(value+2) + 4))**value+3
4 |
5 | def g_function(value):
6 | return (4 + 2) + value**2
7 | def main():
8 | """Love you, I say, good bye my dearest!"""
9 | value = int(input())
10 | print(f_function(g_function(value)))
11 | main()
12 |
--------------------------------------------------------------------------------
/Practice-Final/Ranking the scores.py:
--------------------------------------------------------------------------------
1 | """Thank you ขอบคุณที่เราได้พบเจอกัน"""
2 | def main():
3 | """Love you, I say, good bye my dearest!"""
4 | ranks = [int(i) for i in input().split(",")]
5 | ranked = sorted(ranks, reverse=True)
6 | value = [str(ranked.index(i) + 1) for i in ranks]
7 | string_builder = ","
8 | string_builder = string_builder.join(value)
9 | print(string_builder)
10 | main()
11 |
--------------------------------------------------------------------------------
/Practice-Final/[Onsite-List] Listเลข.py:
--------------------------------------------------------------------------------
1 | """Thank you ขอบคุณที่เราได้พบเจอกัน"""
2 | def main():
3 | """Love you, I say, good bye my dearest!"""
4 | value = int(input())
5 | lst = []
6 | if value < 0:
7 | lst = [int(i) for i in range(0, value - 1, -1)]
8 | else:
9 | lst = [int(i) for i in range(0, value + 1)]
10 | print(lst)
11 | main()
12 |
--------------------------------------------------------------------------------
/Practice-Final/เอาไปใส่ตรงไหนดี.py:
--------------------------------------------------------------------------------
1 | """Thank you ขอบคุณที่เราได้พบเจอกัน"""
2 | def main():
3 | """Love you, I say, good bye my dearest!"""
4 | value = int(input())
5 | print(14 + (value**2 + 12) * (3 + 2))
6 | main()
7 |
--------------------------------------------------------------------------------
/Practice-Final/เอาไปใส่ตรงไหนดีทำไมมันยากจัง.py:
--------------------------------------------------------------------------------
1 | """Thank you ขอบคุณที่เราได้พบเจอกัน"""
2 | def main():
3 | """Love you, I say, good bye my dearest!"""
4 | print(50)
5 | print(1)
6 | print(41)
7 | print("-18")
8 | print(10)
9 | print(4)
10 | main()
11 |
--------------------------------------------------------------------------------
/Practice-Midterm/AB Problem.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | a_value = int(input())
5 | b_value = int(input())
6 | print("%d" % (a_value + b_value))
7 | main()
8 |
--------------------------------------------------------------------------------
/Practice-Midterm/ABC.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | from codecs import charmap_encode
3 |
4 |
5 | def main():
6 | """Main function"""
7 | a, b, c = [int(value) for value in input().split()]
8 | text = input()
9 | arr = []
10 | arr.append(a)
11 | arr.append(b)
12 | arr.append(c)
13 | arr.sort()
14 | for character in text:
15 | if character == "A":
16 | print(arr[0], end=" ")
17 | elif character == "B":
18 | print(arr[1], end=" ")
19 | elif character == "C":
20 | print(arr[2], end=" ")
21 |
22 | main()
23 |
--------------------------------------------------------------------------------
/Practice-Midterm/AxB Problem.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | a_val = int(input())
5 | b_val = int(input())
6 | print(a_val * b_val)
7 | main()
8 |
--------------------------------------------------------------------------------
/Practice-Midterm/BUKA.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | x_value = int(input())
5 | operator = input()
6 | y_value = int(input())
7 | if operator == "+":
8 | print("%d" % (x_value + y_value))
9 | elif operator == "*":
10 | print("%d" % (x_value * y_value))
11 | main()
12 |
--------------------------------------------------------------------------------
/Practice-Midterm/Character Checker.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = input()
5 | if value.islower():
6 | print("All Small Letter")
7 | elif value.isupper():
8 | print("All Capital Letter")
9 | else:
10 | print("Mix")
11 | main()
12 |
--------------------------------------------------------------------------------
/Practice-Midterm/DATUM.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = input().split()
5 | day = int(value[0])
6 | month = int(value[1])
7 |
8 | days = 0
9 | for i in range(1, month):
10 | if i == 4 or i == 6 or i == 9 or i == 11:
11 | days += 30
12 | elif i == 2:
13 | days += 28
14 | else:
15 | days += 31
16 | days += day
17 | if days % 7 == 1:
18 | print("Thursday")
19 | elif days % 7 == 2:
20 | print("Friday")
21 | elif days % 7 == 3:
22 | print("Saturday")
23 | elif days % 7 == 4:
24 | print("Sunday")
25 | elif days % 7 == 5:
26 | print("Monday")
27 | elif days % 7 == 6:
28 | print("Tuesday")
29 | elif days % 7 == 0:
30 | print("Wednesday")
31 | main()
32 |
--------------------------------------------------------------------------------
/Practice-Midterm/Grading.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def calculate_grade(total_score):
3 | """Calculate grade"""
4 | if total_score >= 80:
5 | return "A"
6 | elif total_score >= 75:
7 | return "B+"
8 | elif total_score >= 70:
9 | return "B"
10 | elif total_score >= 65:
11 | return "C+"
12 | elif total_score >= 60:
13 | return "C"
14 | elif total_score >= 55:
15 | return "D+"
16 | elif total_score >= 50:
17 | return "D"
18 | return "F"
19 |
20 | def main():
21 | """Main function"""
22 | score = int(input())
23 | midterm_score = int(input())
24 | final_score = int(input())
25 |
26 | grade = calculate_grade(score + midterm_score + final_score)
27 | print(grade)
28 | main()
29 |
--------------------------------------------------------------------------------
/Practice-Midterm/Great Common Divisor.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import math
3 |
4 | def main():
5 | """Main function"""
6 | value = input().split()
7 | x_val = int(value[0])
8 | y_val = int(value[1])
9 |
10 | print(math.gcd(x_val, y_val))
11 | main()
12 |
--------------------------------------------------------------------------------
/Practice-Midterm/Greatest Common Divisor.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import math
3 |
4 | def main():
5 | """Main function"""
6 | x_value = int(input())
7 | y_value = int(input())
8 |
9 | print(math.gcd(x_value, y_value))
10 | main()
11 |
--------------------------------------------------------------------------------
/Practice-Midterm/Herman.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import math
3 |
4 | def main():
5 | """Main functions"""
6 | radius = int(input())
7 | print("%.6f" %(math.pi*radius**2))
8 | print("%.6f" %(2*radius**2))
9 | main()
10 |
--------------------------------------------------------------------------------
/Practice-Midterm/Kemija.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | text = input()
5 | text = text.replace("apa", "a")
6 | text = text.replace("epe", "e")
7 | text = text.replace("ipi", "i")
8 | text = text.replace("opo", "o")
9 | text = text.replace("upu", "u")
10 | print(text)
11 | main()
12 |
--------------------------------------------------------------------------------
/Practice-Midterm/Kornislav.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = input().split()
5 | for i in range(len(value)):
6 | value[i] = int(value[i])
7 | value.remove(max(value))
8 | print(max(value) * min(value))
9 | main()
10 |
--------------------------------------------------------------------------------
/Practice-Midterm/Least Common Multiple.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import math
3 |
4 | def main():
5 | """Main function"""
6 | x_value = int(input())
7 | y_value = int(input())
8 | lcm = (x_value * y_value) / math.gcd(x_value, y_value)
9 | print("%d" % (lcm))
10 | main()
11 |
--------------------------------------------------------------------------------
/Practice-Midterm/Matrix Addition.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def create_matrix(row):
3 | """Create matrix"""
4 | matrix = []
5 | for _ in range(row):
6 | matrix.append([int(i) for i in input().split()])
7 | return matrix
8 |
9 | def main():
10 | """Main function"""
11 | value = input()
12 | column = int(value.split()[0])
13 | row = int(value.split()[1])
14 | matrix1 = create_matrix(column)
15 | matrix2 = create_matrix(column)
16 | total = [0] * column
17 | for i in range(column):
18 | total[i] = [0] * row
19 | for i in range(column):
20 | for j in range(row):
21 | total[i][j] += matrix1[i][j] + matrix2[i][j]
22 | for i in range(column):
23 | for j in range(row):
24 | print(total[i][j], end=" ")
25 | print()
26 | main()
27 |
--------------------------------------------------------------------------------
/Practice-Midterm/Min Max.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | round = int(input())
5 | min_value = 0
6 | max_value = 0
7 | for i in range(round):
8 | value = int(input())
9 | if i == 0:
10 | #Initialize min_value and max_value
11 | min_value = value
12 | max_value = value
13 | if value < min_value:
14 | min_value = value
15 | if value > max_value:
16 | max_value = value
17 | print("%d" % (min_value))
18 | print("%d" % (max_value))
19 |
20 | main()
21 |
--------------------------------------------------------------------------------
/Practice-Midterm/Modulo.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | arr = []
5 | for _ in range(10):
6 | arr.append(int(input()) % 42)
7 | print(len(set(arr)))
8 |
9 | main()
10 |
--------------------------------------------------------------------------------
/Practice-Midterm/Okviri.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | text = input()
5 | LAYER_1, LAYER_2, LAYER_3 = '.', '.', '#'
6 | for value in text:
7 | LAYER_1 += '.#..'
8 | LAYER_2 += '#.#.'
9 | LAYER_3 += '.' + value + '.#'
10 | for value in range(2, len(text), 3):
11 | LAYER_1 = LAYER_1[:value*4+2] + '*' + LAYER_1[value*4+3:]
12 | LAYER_2 = LAYER_2[:value*4+1] + '*.*' + LAYER_2[value*4+4:]
13 | LAYER_3 = LAYER_3[:value*4] + '*.' + text[value] + '.*' + LAYER_3[value*4+5:]
14 | print(LAYER_1)
15 | print(LAYER_2)
16 | print(LAYER_3)
17 | print(LAYER_2)
18 | print(LAYER_1)
19 | main()
--------------------------------------------------------------------------------
/Practice-Midterm/Pythagorus.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 | def main():
4 | """Main function"""
5 | value = input().split()
6 | x_val = float(value[0])
7 | y_val = float(value[1])
8 |
9 | print("%.6f" % (x_val**2 + y_val**2)**0.5)
10 | main()
11 |
--------------------------------------------------------------------------------
/Practice-Midterm/Reseto.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | x_val, y_val = [int(x) for x in input().split()]
5 | total_xval = int(x_val)
6 | value = []
7 | counter = 0
8 | for i in range(2, total_xval + 1):
9 | value.append(i)
10 | while (len(value) != 0):
11 | point = value[0]
12 | y_list = []
13 | for i in range(0, len(value)):
14 | if value[i] % point == 0:
15 | y_list.append(value[i])
16 | for i in range(0, len(y_list)):
17 | value.remove(y_list[i])
18 | counter += 1
19 | if counter == y_val:
20 | print(y_list[i])
21 | break
22 | main()
23 |
--------------------------------------------------------------------------------
/Practice-Midterm/Seven Dwarves.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 | def main():
4 | """ Main function """
5 | crewmate = [int(input()) for _ in range(9)]
6 | for imposter_a in crewmate:
7 | remaining_crewmate = [*crewmate]
8 | remaining_crewmate.remove(imposter_a)
9 | for imposter_b in remaining_crewmate:
10 | party = [*remaining_crewmate]
11 | party.remove(imposter_b)
12 | if sum(party) == 100:
13 | for i in party:
14 | print(i)
15 | return
16 | print("ERROR")
17 |
18 | main()
--------------------------------------------------------------------------------
/Practice-Midterm/Skocimis.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = input().split()
5 | x_val = int(value[0])
6 | y_val = int(value[1])
7 | z_val = int(value[2])
8 |
9 | x_value = z_val - y_val - 1
10 | y_value = y_val - x_val - 1
11 | if x_value == y_value:
12 | print(x_value)
13 | elif x_value > y_value:
14 | print(x_value)
15 | elif y_value > x_value:
16 | print(y_value)
17 | main()
18 |
--------------------------------------------------------------------------------
/Practice-Midterm/Toppykung.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | num = int(input())
5 | value = []
6 | for _ in range(num):
7 | text = input()
8 | if text not in value:
9 | value.append(text)
10 | value.sort()
11 | for i in value:
12 | print(i)
13 | main()
14 |
--------------------------------------------------------------------------------
/Practice-Midterm/Trik.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def calculate_ball(current, text):
3 | """Calculation of ball"""
4 | if text == "A":
5 | if current == 1:
6 | current = 2
7 | elif current == 2:
8 | current = 1
9 | elif text == "B":
10 | if current == 2:
11 | current = 3
12 | elif current == 3:
13 | current = 2
14 | elif text == "C":
15 | if current == 1:
16 | current = 3
17 | elif current == 3:
18 | current = 1
19 | return current
20 |
21 | def main():
22 | """Main function"""
23 | current = 1
24 | text = input()
25 | for character in text:
26 | current = calculate_ball(current, character)
27 | print(current)
28 | main()
29 |
--------------------------------------------------------------------------------
/Practice-Midterm/X2.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = input().split()
5 | x_one = int(value[0])
6 | average_of_s = int(value[1])
7 | print("%d" % (average_of_s * 2 - x_one))
8 | main()
9 |
--------------------------------------------------------------------------------
/Pre/[Pre] AB.py:
--------------------------------------------------------------------------------
1 | """Hello world PSCP"""
2 |
3 |
4 | def main():
5 | """Main function"""
6 | value_a = int(input())
7 | value_b = int(input())
8 | print(str(value_a+value_b))
9 |
10 |
11 | main()
12 |
--------------------------------------------------------------------------------
/Pre/[Pre] Blackjack.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | x_val = []
5 | y_val = []
6 | amount = int(input())
7 | for _ in range(amount):
8 | card = input()
9 | if card in "jkqJKQ":
10 | card = 10
11 | x_val.append(card)
12 | elif card in "Aa":
13 | y_val.append("A")
14 | else: # number
15 | x_val.append(int(card))
16 | while len(y_val) > 0:
17 | y_val.remove("A")
18 | if sum(x_val) + 11 > 21:
19 | x_val.append(1)
20 | elif sum(x_val) == 10 and len(y_val) == 1:
21 | x_val.append(1)
22 | else:
23 | x_val.append(11)
24 | print(sum(x_val))
25 | main()
26 |
--------------------------------------------------------------------------------
/Pre/[Pre] Hamburger.py:
--------------------------------------------------------------------------------
1 | """Hamburger"""
2 |
3 | def main():
4 | """Main function"""
5 | value_left = int(input())
6 | value_right = int(input())
7 |
8 | left_hamburger = "|"*value_left
9 | right_hamburger = "|"*value_right
10 |
11 | meat = "*"*(value_left*2 + value_right*2)
12 | print(left_hamburger + meat + right_hamburger)
13 |
14 |
15 | main()
16 |
--------------------------------------------------------------------------------
/Pre/[Pre] Kayak.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def closest(position):
3 | """ Keep position """
4 | num_min = position[1] - position[0]
5 | position_1 = 0
6 | position_2 = 1
7 | for i in range(len(position)-1):
8 | if position[i+1] - position[i] < num_min:
9 | num_min = position[i+1] - position[i]
10 | position_1 = i
11 | position_2 = i+1
12 | return num_min, position_1, position_2
13 |
14 | def main():
15 | """ Main function """
16 | number = int(input())
17 | weight = input().split()
18 | position = []
19 | num_min, position_1, position_2 = 0, 0, 0
20 | summation = 0
21 | for i in range(len(weight)):
22 | position.append(int(weight[i]))
23 | position.sort()
24 | for _ in range(number-1):
25 | num_min, position_1, position_2 = closest(position)
26 | summation += num_min
27 | position.remove(position[position_2])
28 | position.remove(position[position_1])
29 | print(summation)
30 |
31 | main()
32 |
--------------------------------------------------------------------------------
/Pre/[Pre] LeftArrow.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 | def main():
4 | """Main function"""
5 |
6 | value_x = int(input())
7 | value_y = int(input())
8 | height = int((value_y-1)/2)
9 | final_height = height
10 | for _ in range(0, height+1):
11 | print((" ")*height+("*")*value_x)
12 | height -= 1
13 | for _ in range(0, final_height+1):
14 | height += 1
15 | if height >= 1:
16 | print((" ")*height+("*")*value_x)
17 | main()
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PSCP - Python
2 | This repository consists of codes of "Problem Solving and Computer Programming (PSCP)" subject, School of Information Techonology, King Mongkut's Institute of Technology Ladkrabang (KMITL).
3 |
4 |
5 | _____
6 |
7 | Note:
8 |
9 | - Only for Viewing and Studying.
10 | - Please DO NOT copy.
11 |
12 |
13 | _____
14 |
--------------------------------------------------------------------------------
/Week11/AlmostMean.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | score = []
5 | data = []
6 | mean = 0
7 | value = 0
8 | countable = int(input())
9 | for _ in range(countable):
10 | txt = input()
11 | data.append(txt)
12 | txt = txt.split("\t")
13 | score.append(float(txt.pop(1)))
14 | mean = (sum(score))/countable
15 | student_of_mean_score = sorted(score)
16 | student_of_mean_score.reverse()
17 | for i in student_of_mean_score:
18 | if i <= mean:
19 | value = score.index(i)
20 | print(data[value])
21 | break
22 | main()
23 |
--------------------------------------------------------------------------------
/Week11/AscendingSort.py:
--------------------------------------------------------------------------------
1 | '''AscendingSort'''
2 | def main():
3 | '''AscendingSort'''
4 | value = []
5 | for _ in range(5):
6 | num = int(input())
7 | value.append(num)
8 | value.sort()
9 | print(*value, sep="\n")
10 | main()
11 |
--------------------------------------------------------------------------------
/Week11/Backward.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = []
5 | while True:
6 | x_val = input()
7 | if x_val == "NULL":
8 | break
9 | value.append(x_val)
10 | value.reverse()
11 | print(*value, sep="\n")
12 | main()
13 |
--------------------------------------------------------------------------------
/Week11/BookWorm.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main functions"""
4 | countable = int(input())
5 | for _ in range(countable):
6 | minute = float(input())
7 | value = sorted([float(input()) for _ in range(int(input()))])
8 | i = 0
9 | for i in range(len(value)):
10 | if sum(value[:i+1]) > minute:
11 | break
12 | i += 1
13 | print(i)
14 | main()
15 |
--------------------------------------------------------------------------------
/Week11/BusStop I.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | amount = int(input())
5 | count = int(input())
6 | passenger_of_list_string = [] #list var is string
7 | passenger_of_list_integer = [] #list var is integer
8 | at_home = 0
9 | for _ in range(count):
10 | bus = input().split()
11 | passenger_of_list_string.append(bus)
12 | passenger_of_list_string.sort(key=lambda i: int(i[0]))
13 | for i in passenger_of_list_string:
14 | stage_bus_stop = int(i[0])
15 | if len(passenger_of_list_integer) != 0:
16 | passenger_of_list_integer2 = passenger_of_list_integer.copy()
17 | for arrive in passenger_of_list_integer:
18 | if arrive == stage_bus_stop:
19 | passenger_of_list_integer2.remove(arrive)
20 | at_home += 1
21 | passenger_of_list_integer = passenger_of_list_integer2
22 | for j in range(1, len(i)):
23 | if len(passenger_of_list_integer) == amount:
24 | break
25 | if stage_bus_stop < int(i[j]):
26 | passenger_of_list_integer.append(int(i[j]))
27 | print(at_home)
28 | main()
29 |
--------------------------------------------------------------------------------
/Week11/Cat Parade.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | countable = []
5 | specific_of_cat = []
6 | while True:
7 | text = input().split(", ")
8 | if text == ["IT\'S A DOG"]:
9 | countable.pop()
10 | continue
11 | if text == ['END']:
12 | break
13 | countable += text
14 | for i in range(len(countable)):
15 | if countable[i] not in specific_of_cat:
16 | specific_of_cat.append(countable[i])
17 | specific_of_cat.sort()
18 | for i in range(len(specific_of_cat)):
19 | print("%s %d %d"%(specific_of_cat[i], (countable.index(specific_of_cat[i])+1),\
20 | countable.count(specific_of_cat[i])))
21 | main()
22 |
--------------------------------------------------------------------------------
/Week11/CuteCat CuteFox.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def compare_length(dict_cat, txt):
3 | """Compare Length Functions"""
4 | return len([few for few in dict_cat.values() if txt in few])
5 |
6 | def main():
7 | """Main functions"""
8 | countable, dict_cat, cat_result = int(input()), {}, {}
9 | for _ in range(countable):
10 | txt = str(input())
11 | if len(txt.split('"')) > len(txt.split("'")):
12 | dict_cat[txt.split('"')[1]] = txt.split('"')[3]
13 | else:
14 | dict_cat[txt.split("'")[1]] = txt.split("'")[3]
15 | count_of_cat, count_of_fox = compare_length(dict_cat, "Cat"), compare_length(dict_cat, "Fox")
16 | check_of_cat, check_of_fox, count = "Cat01" in dict_cat.values(), \
17 | "Fox01" in dict_cat.values(), 0
18 | if count_of_cat == 0 or check_of_cat == 0:
19 | cat_result["Garfield"] = "Cat01"
20 | if count_of_fox == 0 or check_of_fox == 0:
21 | cat_result["Fubuki"] = "Fox01"
22 | for key, value in sorted(dict_cat.items(), key=lambda x: x[1]):
23 | if check_of_fox == 0 and value.count("Fox") >= 1 and count == 0:
24 | count += 1
25 | cat_result["Fubuki"] = "Fox01"
26 | cat_result[key] = value
27 | count_of_cat, count_of_fox = compare_length(cat_result, "Cat"), \
28 | compare_length(cat_result, "Fox")
29 | cat, fox = {}, {}
30 | for key, value in cat_result.items():
31 | if value.count("Cat") >= 1:
32 | cat.update({int(value.split("Cat")[1]): [key, value]})
33 | elif value.count("Fox") >= 1:
34 | fox.update({int(value.split("Fox")[1]): [key, value]})
35 | print("Cat : %d\nFox : %d" %(count_of_cat, count_of_fox))
36 | for cry in sorted(cat):
37 | print(cat[cry][0] + " : " + cat[cry][1])
38 | for cry in sorted(fox):
39 | print(fox[cry][0] + " : " + fox[cry][1])
40 | main()
41 |
--------------------------------------------------------------------------------
/Week11/Diamond I.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main functions"""
4 | count_a = int(input())
5 | count_b = int(input())
6 | value = []
7 | attempted = []
8 | for _ in range(count_a):
9 | diamond = input().split()
10 | value.append(diamond)
11 | for i in range(count_b):
12 | calculate = 0
13 | for j in value:
14 | calculate += int(j[i])
15 | attempted.append(calculate)
16 | print(max(attempted))
17 | main()
18 |
--------------------------------------------------------------------------------
/Week11/Kabata.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | count = int(input())
5 | for _ in range(count):
6 | word = input()
7 | word = word.replace('baka', '-').replace("bakka", "").\
8 | replace("ta", "").replace("ba", "").replace("ka", "")
9 | if word == "":
10 | print("yes")
11 | else:
12 | print("no")
13 | main()
14 |
--------------------------------------------------------------------------------
/Week11/LastStand.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = input()
5 | value = value.replace("[", "")
6 | value = value.replace("]", "")
7 | value = value.split(",")
8 | for text in value:
9 | print(text[-1])
10 | main()
11 |
--------------------------------------------------------------------------------
/Week11/LineSorting.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | count = int(input())
5 | value = []
6 | for _ in range(1, count + 1):
7 | value.append(input())
8 | value = sorted(value, key=lambda x: (len(x), x))
9 | print(*value, sep="\n")
10 | main()
11 |
--------------------------------------------------------------------------------
/Week11/Median.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def median(value):
3 | """Midpoint of a list"""
4 | length_of_list = len(value)
5 | x_value = sorted(value)
6 | return (x_value[length_of_list//2-1]/2.0+x_value[length_of_list//2]/2.0,\
7 | x_value[length_of_list//2])[length_of_list % 2] if length_of_list else None
8 |
9 | def main():
10 | """Main function"""
11 | countable = int(input())
12 | numbers = []
13 | for _ in range(countable):
14 | numbers.append(int(input()))
15 | print("%.1f" % median(numbers))
16 | main()
17 |
--------------------------------------------------------------------------------
/Week11/MissingNumber.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | x_val = []
5 | checked = []
6 | value = int(input())
7 | for i in range(value+1):
8 | checked.append(i)
9 | for _ in range(value):
10 | value1 = int(input())
11 | x_val.append(value1)
12 | if value1 == 0:
13 | break
14 | x_val.sort()
15 | for i in x_val:
16 | checked.remove(i)
17 | for i in checked:
18 | print(i)
19 | main()
20 |
--------------------------------------------------------------------------------
/Week11/Muddled Menu.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | menu = []
5 | while True:
6 | course = input()
7 | if course == "DONE":
8 | break
9 | elif course == "CLOSED":
10 | return print("Full Course: [] Reversed: []")
11 | elif course == "SOMETHING'S WRONG":
12 | menu.clear()
13 | continue
14 | elif course[0:10:] == "Can't do: ":
15 | menu.remove(course[10::])
16 | else:
17 | text = course.split(" #")
18 | if text[1].isnumeric():
19 | menu.insert(int(text[1])-1, text[0])
20 | else:
21 | menu.append(text[0])
22 | print("Full Course: " + str(menu), end=" ")
23 | menu.reverse()
24 | print("Reversed: " + str(menu))
25 | main()
26 |
--------------------------------------------------------------------------------
/Week11/PickThem.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import json
3 |
4 | def main():
5 | """Main function"""
6 | value = []
7 | x_val = json.loads(input())
8 | can_find_value = False
9 | for i in range(len(x_val)):
10 | y_val = int(x_val[i])
11 | if y_val % 2 == 0:
12 | value.append(int(x_val[i]))
13 | can_find_value = True
14 | if can_find_value:
15 | print(*value, sep="\n")
16 | else:
17 | print("Nope")
18 | main()
19 |
--------------------------------------------------------------------------------
/Week11/PickThemAgain.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | x_val = []
5 | value = input().split(" ")
6 | can_find_value = False
7 | for i in range(len(value)):
8 | y_val = int(value[i])
9 | if y_val % 3 == 0 or y_val % 5 == 0:
10 | x_val.append(int(value[i]))
11 | can_find_value = True
12 | x_val.reverse()
13 | if can_find_value:
14 | print(*x_val, sep="\n")
15 | else:
16 | print("Nope")
17 | main()
18 |
--------------------------------------------------------------------------------
/Week11/Point Sorting.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | count = int(input())
5 | for _ in range(count):
6 | next_value = int(input())
7 | value = []
8 | for _ in range(next_value):
9 | text = input().split()
10 | changed_integer_to_list = []
11 | changed_integer_to_list.append(int(text[0]))
12 | changed_integer_to_list.append(int(text[1]))
13 | value.append(changed_integer_to_list)
14 | value.sort(reverse=True, key=lambda value: value[1])
15 | value.sort(key=lambda value: value[0]+value[1])
16 | for i in value:
17 | for j in i:
18 | print(j, end=" ")
19 | print()
20 | main()
21 |
--------------------------------------------------------------------------------
/Week11/RemoveTag.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | message = input().replace("<", "$<").replace(">", ">$").split("$")
5 | check = list(filter(lambda x, ok="<": ok not in x, message))
6 | value = ' '.join(check)
7 | print(value.split())
8 | main()
9 |
--------------------------------------------------------------------------------
/Week11/Runner.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | distance = float(input())
5 | count = int(input())
6 | value = []
7 | runner = []
8 | for _ in range(count):
9 | player = input().split(" ")
10 | value.append(player)
11 | value2 = value.copy()
12 | value.sort(key=lambda i: float(i[0]), reverse=True)
13 | for i in value:
14 | runner.append((distance-float(i[1]))/float(i[0]))
15 | print(value2.index(value[runner.index(min(runner))])+1)
16 | main()
17 |
--------------------------------------------------------------------------------
/Week11/Tuple's Sad life.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | sequence = tuple(input().split(" "))
5 | find_index = input()
6 | for _ in range(sequence.count(find_index)):
7 | for _ in range(sequence.count(find_index)):
8 | print(int(sequence.index(find_index)), end=" ")
9 | print()
10 | main()
11 |
--------------------------------------------------------------------------------
/Week12/All_Primes.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value_1 = int(input())
5 | increment = 0
6 | for i in range(1, value_1 + 1):
7 | if i > 1:
8 | for j in range(2, i):
9 | if i % j == 0:
10 | break
11 | else:
12 | increment += 1
13 | print(increment)
14 | main()
15 |
--------------------------------------------------------------------------------
/Week12/BreachTheDoor.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | print(*filter(lambda a: len(a) > 6, (["".join(j for j in i if \
5 | j.isalpha()) for i in input().split(" ")])))
6 | main()
7 |
--------------------------------------------------------------------------------
/Week12/Calculator V2.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = int(input())
5 | count = len(str(value))
6 | count_1 = 1
7 | count_9 = 9
8 | tap_num = 0
9 |
10 | if value == 1:
11 | print(1)
12 | quit()
13 | for i in range(1, count):
14 | howmany = (count_9 - count_1)+1
15 | tap_num += howmany * i
16 | count_1 = int(str(count_1) + "0")
17 | count_9 = int(str(count_9) + "9")
18 |
19 | last_count = ((value - count_1) + 1) * count
20 | total = (tap_num + last_count) + value
21 | print(total)
22 | main()
23 |
--------------------------------------------------------------------------------
/Week12/Classify.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | student = []
5 | while True:
6 | value = input()
7 | if value == "END":
8 | break
9 | student.append(value[:4])
10 | old_year = 0
11 | for i in sorted(set(student)):
12 | year = i[:2]
13 | print(year if year != old_year else "--", int(i[2:4]), student.count(i))
14 | old_year = year
15 | main()
16 |
--------------------------------------------------------------------------------
/Week12/CoPrime V1.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value_1 = int(input())
5 | value_2 = int(input())
6 | check = 1
7 | for i in range(1, value_1 + 1):
8 | if value_1 % i == 0 and value_2 % i == 0:
9 | check = i
10 | if check == 1:
11 | print("YES")
12 | print(check)
13 | else:
14 | print("NO")
15 | print(check)
16 | main()
17 |
--------------------------------------------------------------------------------
/Week12/Coke V2.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | original_cost = int(input())
5 | promotion_cap_of_coke = int(input())
6 | special_cost = int(input())
7 | amount = int(input())
8 |
9 | if promotion_cap_of_coke == 0:
10 | print(original_cost*amount)
11 | quit()
12 | if amount == 0:
13 | print(0)
14 | quit()
15 |
16 | howmany = (amount - 1)
17 | loop_count = howmany // promotion_cap_of_coke
18 | howmany_left = howmany % promotion_cap_of_coke
19 | price2loop = (original_cost*(promotion_cap_of_coke-1)) + special_cost
20 |
21 | total = original_cost + (loop_count * price2loop) + (howmany_left * original_cost)
22 | print(total)
23 | main()
24 |
--------------------------------------------------------------------------------
/Week12/Difference.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | set_n = set()
5 | set_m = set()
6 | num_n = int(input())
7 | num_m = int(input())
8 | for _ in range(num_n):
9 | set_n.add(int(input()))
10 | for _ in range(num_m):
11 | set_m.add(int(input()))
12 | value = set_n.difference(set_m)
13 | value = sorted(value)
14 | for i in value:
15 | print(i, end=" ")
16 | main()
17 |
--------------------------------------------------------------------------------
/Week12/Duplicate I.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | list_group1 = set()
5 | list_group2 = set()
6 | num_m = int(input())
7 | num_n = int(input())
8 | for _ in range(num_m):
9 | data_m = input()
10 | list_group1.add(data_m)
11 | for _ in range(num_n):
12 | data_n = input()
13 | list_group2.add(data_n)
14 | ans = list_group1.intersection(list_group2)
15 | ans_real = (sorted((ans), reverse=True))
16 | if ans == set(): #set()
17 | print("Nope")
18 | else:
19 | for i in ans_real:
20 | print(i)
21 | main()
22 |
--------------------------------------------------------------------------------
/Week12/Filter.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import json
3 |
4 | def main():
5 | """Main function"""
6 | value = input()
7 | json_paser = ['0']
8 | test = float(input())
9 | value = json.loads(value)
10 | for key in value:
11 | if value[key] >= test:
12 | json_paser.append('%s %.2f' %(key, float(value[key])))
13 | else:
14 | pass
15 | if len(json_paser) >= 2:
16 | json_paser.remove('0')
17 | json_paser.sort()
18 | for i in json_paser:
19 | if i == "0":
20 | print("Nope")
21 | break
22 | else:
23 | print("%s\t%.2f" %(i[0:8], float(i[9::])))
24 | main()
25 |
--------------------------------------------------------------------------------
/Week12/GCD_v1.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | gcd = int(input())
5 | value = int(input())
6 | for i in range(100000, 0, -1):
7 | if gcd % i == 0 and value % i == 0:
8 | print(i)
9 | break
10 | main()
11 |
--------------------------------------------------------------------------------
/Week12/HorizontalHistogram.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def sort_by_value(var):
3 | """Sort by value"""
4 | char = var[0]
5 | return ord(char) + (100 if char.isupper() else 0)
6 |
7 | def main(string):
8 | """Main function"""
9 | for char, count in sorted({i: string.count(i) for i in string}.items(), key=sort_by_value):
10 | print(char, ":", "".join(["-" if i % 5 else "-|" for i in range(1, count+1)]).rstrip("|"))
11 | main(input())
12 |
--------------------------------------------------------------------------------
/Week12/Impostor.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import json
3 |
4 | def main():
5 | """Main function"""
6 | player, dead, alive, impostor = {}, {}, {}, 0
7 | while True:
8 | txt = input()
9 | if txt.lower() == "start":
10 | continue
11 | if txt.lower() == "end":
12 | break
13 | if txt[0] == "{":
14 | player.update(json.loads(txt))
15 | else:
16 | dead.update({txt:player[txt]})
17 | for i in player:
18 | if i not in dead:
19 | alive.update({i:player[i]})
20 | for i in alive:
21 | if player[i] == "Impostor":
22 | impostor += 1
23 | print(str(impostor)+" Impostor Remains", "***Alive***", sep="\n")
24 | for i in sorted(alive.items(), key=lambda item: item[0]):
25 | print(*i, sep=" : ")
26 | print("***Dead***")
27 | for i in sorted(dead.items(), key=lambda item: item[0]):
28 | print(*i, sep=" : ")
29 | main()
30 |
--------------------------------------------------------------------------------
/Week12/LetterFrequency.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import string
3 |
4 | def main():
5 | """Main function"""
6 | text = input().lower().replace(" ", "")
7 | value = list(filter(lambda a: a in string.ascii_letters, text))
8 | value = max(set(text), key=text.count)
9 | print(value)
10 | main()
11 |
--------------------------------------------------------------------------------
/Week12/MissingCard I.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | text = ["A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3", "2"]
5 | card = []
6 | for i in text:
7 | card_s = i + "S"
8 | card_h = i + "H"
9 | card_d = i + "D"
10 | card_c = i + "C"
11 | card.append(card_s)
12 | card.append(card_h)
13 | card.append(card_d)
14 | card.append(card_c)
15 | for _ in range(51):
16 | missed_card = str(input())
17 | if missed_card in card:
18 | card.remove(missed_card)
19 | print(card[0])
20 | main()
21 |
--------------------------------------------------------------------------------
/Week12/Olympic.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | countries = dict()
5 | for _ in range(int(input())):
6 | value = input().split(" ")
7 | countries[value[0]] = tuple(map(int, value[1:]))
8 | sorted_countries = sorted(countries.items(), key=lambda a: sum(a[1]), reverse=True)
9 | sorted_countries.sort(key=lambda a: a[0])
10 | sorted_countries.sort(key=lambda a: a[1], reverse=True)
11 | rank = 0
12 | keep = 0
13 | old = 0
14 | for country, score in sorted_countries:
15 | score_sum = sum(score)
16 | score = " ".join(map(str, score))
17 | if score != old:
18 | rank += keep
19 | keep = 0
20 | rank += 1
21 | elif rank != 0:
22 | keep += 1
23 | print(rank, country, score, score_sum)
24 | old = score
25 | main()
26 |
--------------------------------------------------------------------------------
/Week12/Safe.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def rotate_down(correct_text, lock_text):
3 | """Rotate down"""
4 | rodown = 0
5 | while lock_text != correct_text:
6 | if lock_text >= 25:
7 | lock_text = -1
8 | rodown += 1
9 | lock_text += 1
10 | return rodown
11 | def rotate_up(correct_text, lock_text):
12 | """Rotate up"""
13 | roup = 0
14 | while lock_text != correct_text:
15 | if lock_text <= 0:
16 | lock_text = 26
17 | roup += 1
18 | lock_text -= 1
19 | return roup
20 | def main(correct, lock):
21 | """Safe"""
22 | count = 0
23 | for i in range(len(correct)):
24 | correct_text = ord(correct[i])-65
25 | lock_text = ord(lock[i])-65
26 | if correct_text != lock_text:
27 | rodown = rotate_down(correct_text, lock_text)
28 | roup = rotate_up(correct_text, lock_text)
29 | if roup <= rodown:
30 | count += roup
31 | elif rodown < roup:
32 | count += rodown
33 | print(count)
34 | main(input().upper(), input().upper())
35 |
--------------------------------------------------------------------------------
/Week12/Seeker.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | text = input()
5 | check = ""
6 | value = 0
7 | for i in text:
8 | if i.isdigit() == True:
9 | check += i
10 | else:
11 | if check == "":
12 | value += 0
13 | else:
14 | value += int(check)
15 | check = ""
16 | if check.isdigit() == True:
17 | print(value + int(check))
18 | else:
19 | print(value)
20 | main()
21 |
--------------------------------------------------------------------------------
/Week12/WordSequence I.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | text = input()
5 | for i in range(len(text)):
6 | print(text[0:i+1])
7 | main()
8 |
--------------------------------------------------------------------------------
/Week12/WordSequence II.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | text1 = input()
5 | text2 = input()
6 | for i in range(0, max(len(text1), len(text2)) + 1):
7 | print(text2[:i] + text1[i:])
8 | main()
9 |
--------------------------------------------------------------------------------
/Week12/isprime_small.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = int(input())
5 | if value > 1:
6 | for i in range(2, value):
7 | if value % i == 0:
8 | print("No")
9 | break
10 | else:
11 | print("Yes")
12 | else:
13 | print("No")
14 | main()
15 |
--------------------------------------------------------------------------------
/Week13/3nPlus1.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def calculate_length(num):
3 | """Calculate the length of the value"""
4 | value = []
5 | while num != 1:
6 | value.append(num)
7 | if num % 2 == 0:
8 | num = num // 2
9 | else:
10 | num = 3 * num + 1
11 | value.append(1)
12 | return len(value)
13 |
14 | def main():
15 | """ Main function """
16 | arr = []
17 | while True:
18 | value = int(input())
19 | if value == 0:
20 | break
21 | arr.append(value)
22 | for i in arr:
23 | print(calculate_length(i))
24 | main()
25 |
--------------------------------------------------------------------------------
/Week13/Amicable.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def proper_divisor(number):
3 | """ Find sum of proper """
4 | proper = 1
5 | for i in range(2, int(number**0.5) + 1):
6 | if number % i == 0:
7 | proper += i + number // i
8 | return proper
9 |
10 | def main(range_total, amicable):
11 | """ Main function """
12 | for i in range(2, range_total + 1):
13 | if i not in amicable:
14 | number = proper_divisor(i)
15 | if proper_divisor(number) == i and i != number:
16 | amicable.append(i)
17 | amicable.append(number)
18 | print(sum(amicable))
19 | main(int(input()), [])
20 |
--------------------------------------------------------------------------------
/Week13/AndAgainAndAgainAndAgainAndAgainAndAgainAndAgain.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | x_val = []
5 | value = input().replace(".", "")
6 | arr = value.split()
7 | for raw in arr:
8 | total = raw.count("a") + raw.count("e") + raw.count("i") + raw.count("o") + raw.count("u")
9 | if total >= 2:
10 | x_val.append(raw)
11 | if len(x_val) == 0:
12 | x_val.append("Nope")
13 | x_val.sort()
14 | for raw in x_val:
15 | print(raw)
16 | main()
17 |
--------------------------------------------------------------------------------
/Week13/Binary.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def decimal_to_base_two(decimal):
3 | """ Decimal to BaseTwo """
4 | base_two = []
5 | while decimal > 0:
6 | base_two.append(decimal % 2)
7 | decimal //= 2
8 | base_two.reverse()
9 | return base_two
10 |
11 | def main():
12 | """ Main function """
13 | num = int(input())
14 | if num == 0:
15 | print(0)
16 | for raw in decimal_to_base_two(num):
17 | print(raw, end='')
18 | main()
19 |
--------------------------------------------------------------------------------
/Week13/CaesarV1.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import string
3 |
4 | def caesar_cipher(raw, shift):
5 | """Caesar Cipher"""
6 | result = ""
7 | for i in raw:
8 | if i in string.ascii_letters:
9 | if i.isupper():
10 | c_index = ord(i) - ord("A")
11 | new_index = (c_index + shift) % 26
12 | new_unicode = new_index + ord("A")
13 | new_char = chr(new_unicode)
14 | result = result + new_char
15 | else:
16 | if i != " ":
17 | c_index = ord(i) - ord("a")
18 | new_index = (c_index + shift) % 26
19 | new_unicode = new_index + ord("a")
20 | new_char = chr(new_unicode)
21 | result = result + new_char
22 | else:
23 | result += i
24 | else:
25 | result += i
26 | return result
27 |
28 | def main():
29 | """Main function"""
30 | key = int(input())
31 | word = input()
32 | result = caesar_cipher(word, key)
33 | print(result)
34 | main()
35 |
--------------------------------------------------------------------------------
/Week13/CaeserV2.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def check(result, words):
3 | """ Check word is in sentence """
4 | for word in words:
5 | if word in result:
6 | return True
7 | return False
8 |
9 | def main():
10 | """ Main function """
11 | encoded = input()
12 |
13 | lower = "abcdefghijklmnopqrstuvwxyz"
14 | upper = lower.upper()
15 |
16 | words = ['The', 'the', 'What', 'what', 'Where', 'where', 'When', 'when']
17 | result = ""
18 | while 1:
19 | for char in encoded:
20 | if char.isupper():
21 | result += upper[(upper.index(char) + 1) % 26]
22 | elif char.islower():
23 | result += lower[(lower.index(char) + 1) % 26]
24 | else:
25 | result += char
26 | encoded = result
27 | if check(result, words):
28 | break
29 | result = ""
30 | print(encoded)
31 | main()
32 |
--------------------------------------------------------------------------------
/Week13/CircularPrime.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def isprime(number):
3 | """ Find that number is prime or not """
4 | if number == 1:
5 | return False
6 | for i in range(2, int(number ** 0.5) + 1):
7 | if number % i == 0:
8 | return False
9 | return True
10 |
11 | def circular(number):
12 | """ Find that is circular or not """
13 | if not isprime(number):
14 | return 0
15 | number_str = str(number)
16 | digits = len(number_str) - 1
17 | for _ in range(digits):
18 | number_str = number_str[-1] + number_str[:-1]
19 | if not isprime(int(number_str)):
20 | return 0
21 | return number
22 |
23 | def main():
24 | """ Main function """
25 | number = int(input())
26 | result = [circular(x) for x in range(1, number + 1)]
27 | print(sum(result))
28 | main()
29 |
--------------------------------------------------------------------------------
/Week13/ClockHands.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | hour = int(input())
5 | seconds = int(input())
6 | hour *= 5
7 | hour += seconds / 12
8 | hour %= 60
9 | print(seconds <= hour < seconds+1)
10 | main()
11 |
--------------------------------------------------------------------------------
/Week13/Day2011.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | date = int(input())
5 | month = int(input())
6 | number = 0
7 | data = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30]
8 | for i in range(month):
9 | number += data[i]
10 | value = (number + date) % 7
11 | if value == 1:
12 | print("Saturday")
13 | elif value == 2:
14 | print("Sunday")
15 | elif value == 3:
16 | print("Monday")
17 | elif value == 4:
18 | print("Tuesday")
19 | elif value == 5:
20 | print("Wednesday")
21 | elif value == 6:
22 | print("Thursday")
23 | else:
24 | print("Friday")
25 | main()
26 |
--------------------------------------------------------------------------------
/Week13/Divide3Or5.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | num = int(input())
5 | value = []
6 | for i in range(1, num + 1):
7 | if i % 3 == 0 or i % 5 == 0:
8 | value.append(i)
9 | print(sum(value))
10 | main()
11 |
--------------------------------------------------------------------------------
/Week13/FibonacciRecursionV1.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def fibonacci(idx):
3 | """ Fibonacci function """
4 | if idx <= 0:
5 | return abs(idx)
6 | return fibonacci(idx-1) + fibonacci(idx-2)
7 |
8 | def main():
9 | """ Main function """
10 | value = int(input())
11 | print(fibonacci(value))
12 | main()
13 |
--------------------------------------------------------------------------------
/Week13/FibonaciiRecursionV2.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def fibonacci(number):
3 | """ Return fibonacci values for given number """
4 | data = {0:0, 1:1}
5 | if number in data:
6 | return data[number]
7 | if number > 500:
8 | fibonacci(number - 500)
9 | res = fibonacci(number-2) + fibonacci(number-1)
10 | data[number] = res
11 | return res
12 |
13 | def main():
14 | """ Main function """
15 | number = int(input())
16 | result = fibonacci(number)
17 | print(result)
18 | main()
19 |
--------------------------------------------------------------------------------
/Week13/Flatten.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import json
3 |
4 | def main(value: list):
5 | """ Main function """
6 | black_pink = []
7 | for raw in value:
8 | if isinstance(raw, list):
9 | black_pink += main(raw)
10 | else:
11 | black_pink.append(raw)
12 | black_pink.sort(reverse=True)
13 | return black_pink
14 |
15 | print(main(json.loads(input())))
16 |
--------------------------------------------------------------------------------
/Week13/GCD_v2.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | gcd = int(input())
5 | value = int(input())
6 | while value != 0:
7 | gcd, value = value, gcd % value
8 | print(gcd)
9 | main()
10 |
--------------------------------------------------------------------------------
/Week13/Ink.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import math
3 |
4 | def main():
5 | """ Main function """
6 | grow, count = [int(x) for x in input().split()]
7 |
8 | areas = []
9 | for _ in range(count):
10 | posx, posy = [int(x) for x in input().split()]
11 | result = (posx ** 2 + posy ** 2) ** 0.5
12 | result = 3.1416 * result ** 2
13 | areas.append(result)
14 |
15 | for area in areas:
16 | print(math.ceil(area/grow))
17 | main()
18 |
--------------------------------------------------------------------------------
/Week13/OneTwo.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def one_two(value):
3 | """OneTwo Function"""
4 | if value == 1:
5 | return "1"
6 | elif value == 2:
7 | return "2"
8 | else:
9 | return one_two(value - 1) + one_two(value - 2)
10 |
11 | def main():
12 | """ Main function """
13 | print(one_two(int(input())))
14 | main()
15 |
--------------------------------------------------------------------------------
/Week13/PedPonFire.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import math
3 |
4 | def main():
5 | """ Main function """
6 | total = int(input())
7 | duck = []
8 | for _ in range(total):
9 | duck.append(int(input()))
10 | abstract = int(input())
11 | duck.sort()
12 | set_duck = sorted(set(duck))
13 | check = duck.count(abstract / 2)
14 | answer = 0 if check <= 1 else math.factorial(check) // (math.factorial(check - 2) \
15 | * math.factorial(2))
16 | for i in set_duck:
17 | if i >= abstract / 2:
18 | break
19 | answer += duck.count(abstract - i) * duck.count(i)
20 | print(answer)
21 | main()
22 |
--------------------------------------------------------------------------------
/Week13/Perfect.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def isprime(number):
3 | """ Find that number is prime or not """
4 | if number == 1:
5 | return False
6 | for i in range(2, int(number ** 0.5) + 1):
7 | if number % i == 0:
8 | return False
9 | return True
10 |
11 | def perfect(number):
12 | """ Calculate that is perfect number or not """
13 | perfects = []
14 | for count in range(2, number):
15 | if isprime(count):
16 | perfect_number = (2 ** (count - 1)) * ((2 ** count) - 1)
17 | if perfect_number > number:
18 | break
19 | elif perfect_number <= number and perfect_number not in perfects:
20 | perfects.append(perfect_number)
21 | return sum(perfects)
22 |
23 | def main():
24 | """ Main function """
25 | number = int(input())
26 | print(perfect(number))
27 | main()
28 |
--------------------------------------------------------------------------------
/Week13/RectangleArea.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | rec1x2, rec1y2, width1, height1 = [int(x) for x in input().split()]
5 | rec1x1 = rec1x2 + width1
6 | rec1y1 = rec1y2 + height1
7 | rec2x2, rec2y2, width2, height2 = [int(x) for x in input().split()]
8 | rec2x1 = rec2x2 + width2
9 | rec2y1 = rec2y2 + height2
10 |
11 | width = max(0, min(rec1x1, rec2x1) - max(rec1x2, rec2x2))
12 | height = max(0, min(rec1y1, rec2y1) - max(rec1y2, rec2y2))
13 |
14 | result = width * height
15 |
16 | if result > 0:
17 | print(width * height)
18 | else:
19 | print("no overlapping")
20 | main()
21 |
--------------------------------------------------------------------------------
/Week13/Roman.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | maps = {"M": 1000, "D": 500, "C": 100, "L": 50, "X": 10, "V": 5, "I": 1}
5 | value = input()
6 | result = 0
7 | for i, j in enumerate(value):
8 | if (i + 1) == len(value) or maps[j] >= maps[value[i+1]]:
9 | result += maps[j]
10 | else:
11 | result -= maps[j]
12 | print(result)
13 | main()
14 |
--------------------------------------------------------------------------------
/Week13/SMS.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | lis = [["A", "B", "C"], ["D", "E", "F"], ["G", "H", "I"], ["J", "K", "L"], \
5 | ["M", "N", "O"], ["P", "Q", "R", "S"], ["T", "U", "V"], ["W", "X", "Y", "Z"]]
6 | value = []
7 | for _ in range(int(input())):
8 | num1 = int(input())
9 | num2 = int(input())
10 | if num1 == 1:
11 | for _ in range(num2):
12 | if len(value) > 0:
13 | value.pop()
14 | if num1 == 2 or num1 == 3 or num1 == 4 or num1 == 5 or num1 == 6 or num1 == 8 and num2 != 0:
15 | if num2 % 3 == 0:
16 | value.append(lis[num1-2][2])
17 | else:
18 | value.append(lis[num1-2][(num2 % 3)-1])
19 | if num1 == 7 or num1 == 9:
20 | if num2 % 4 == 0:
21 | value.append(lis[num1-2][3])
22 | else:
23 | value.append(lis[num1-2][(num2 % 4)-1])
24 | if len(value) > 0:
25 | return print(*value, sep="")
26 | print("null")
27 | main()
28 |
--------------------------------------------------------------------------------
/Week13/SceneSwitch I.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | turn = 0
5 | warm = 0
6 | count = 0
7 | last = 0
8 | while True:
9 | time = input()
10 | if time == "End":
11 | break
12 | time = float(time)
13 | if time == 0:
14 | turn = 1
15 | continue
16 | if turn == 1:
17 | turn = 0
18 | last = time
19 | continue
20 | if turn == 0 and time - last > 6:
21 | warm = 0
22 | turn = 1
23 | if turn == 0 and time - last <= 6 and warm == 0:
24 | warm = 1
25 | turn = 1
26 | count += 1
27 | if turn == 0 and time - last <= 6 and warm == 1:
28 | warm = 0
29 | turn = 1
30 | print(count)
31 | main()
32 |
--------------------------------------------------------------------------------
/Week13/SqFree.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def checked(num):
3 | """ Check if number is square free """
4 | if num % 2 == 0:
5 | num /= 2
6 | if num % 2 == 0:
7 | return False
8 | for i in range(3, int((num**0.5)+1)):
9 | if num % i == 0:
10 | num /= i
11 | if num % i == 0:
12 | return False
13 | return True
14 |
15 | def main():
16 | """ Main function """
17 | count = 0
18 | for i in range(1, int(input())+1):
19 | if checked(i):
20 | count += 1
21 | print(count)
22 | main()
23 |
--------------------------------------------------------------------------------
/Week13/VerticalHistogram.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | text = input()
5 |
6 | alphabets = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
7 |
8 | result = {}
9 | for alpha in alphabets:
10 | result[alpha] = 0
11 | for char in text:
12 | if char == alpha:
13 | result[alpha] += 1
14 |
15 | maximum = result[max(result, key=result.get)]
16 | for count in range(maximum, 0, -1):
17 | print("%03d" %count, end='')
18 | for alpha in alphabets:
19 | if result[alpha] >= count and result[alpha] != 0:
20 | print(" *", end='')
21 | elif result[alpha] == 0:
22 | continue
23 | else:
24 | print(" ", end='')
25 | print()
26 | print(" " * 3, end='')
27 | for alpha in alphabets:
28 | if result[alpha] != 0:
29 | print(" %s" %alpha, end='')
30 | main()
31 |
--------------------------------------------------------------------------------
/Week13/isPrime_large.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | num = int(input())
5 | if num > 1:
6 | for i in range(2, int(num**0.5)+1):
7 | if num % i == 0:
8 | print("NO")
9 | break
10 | else:
11 | print("YES")
12 | else:
13 | print("NO")
14 | main()
15 |
--------------------------------------------------------------------------------
/Week14/Ball.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | height = float(input())
5 | count = -1
6 | while height >= 0.01:
7 | height = height * 3 / 5
8 | count += 1
9 | print(count)
10 | main()
11 |
--------------------------------------------------------------------------------
/Week14/BiggestIsland.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def flood_fill(i, j, row, col, island):
3 | """Return 1 if (i, j) and its neighors are part of the island, 0 otherwise."""
4 | count = 0
5 | if island[i][j] == 1:
6 | count += 1
7 | island[i][j] = 2
8 | eight_directions = [(1, 0), (-1, 0), (0, 1), (0, -1), (1, 1), (1, -1), (-1, 1), (-1, -1)]
9 | new_positions = [(i+x, j+y) for x, y in eight_directions]
10 | for pos_x, pos_y in new_positions:
11 | if pos_x in range(0, row) and pos_y in range(0, col):
12 | count += flood_fill(pos_x, pos_y, row, col, island)
13 | return count
14 |
15 | def count_island(row, col, island):
16 | """Return total number of islands in the map."""
17 | area = []
18 | for i in range(row):
19 | for j in range(col):
20 | area.append(flood_fill(i, j, row, col, island))
21 | return area
22 |
23 | def main():
24 | """ Main function """
25 | row, col = [int(x) for x in input().split()]
26 | island = [[int(x) for x in input().split()] for _ in range(row)]
27 | print(max(count_island(row, col, island)))
28 | main()
29 |
--------------------------------------------------------------------------------
/Week14/Bowling-Reddit.py:
--------------------------------------------------------------------------------
1 | """IG : few.pz"""
2 | def score_total(pin, score):
3 | """return total score"""
4 | if "/" == score:
5 | return 10 if "X" in pin else 0 if "-" == pin[0] else int(pin[0])
6 | elif "X" == score:
7 | return last_frame(pin)
8 |
9 | def last_frame(pin):
10 | """return score last frame"""
11 | score, score1 = 0, 0
12 | for i in pin:
13 | if i == "X":
14 | score += 10
15 | elif i == "/":
16 | score += 10
17 | score1 = 0
18 | else:
19 | score1 += int(i) if i != "-" else 0
20 | return score + score1
21 |
22 | def main():
23 | """Bowling-Reddit"""
24 | bord = input().split()
25 | bord1 = bord[:-1]+list(bord[-1])
26 | score_bord = [0]
27 | for i in range(9):
28 | pin = bord[i]
29 | score = score_bord[-1]
30 | if "X" in pin:
31 | if "X" not in bord1[i+1]:
32 | score += 10 + score_total(bord[i+1], "X")
33 | else:
34 | count = 0
35 | score += 10
36 | for j in bord1[i+1:]:
37 | if "X" in j:
38 | score += 10
39 | count += 1
40 | else:
41 | score += score_total(j, "/")
42 | break
43 | if count == 2:
44 | break
45 | elif "/" in pin:
46 | score += 10 + score_total(bord[i+1][0], "/")
47 | else:
48 | score += score_total(pin, "X")
49 | score_bord.append(score)
50 | score_bord.append(last_frame(bord[-1])+score_bord[-1])
51 | print(score_bord[-1])
52 |
53 | main()
54 |
--------------------------------------------------------------------------------
/Week14/BreakPassword.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import hashlib
3 |
4 | def main():
5 | """ Main function """
6 | encrypted = input()
7 | for number in range(0, 100000):
8 | value = str("%05d" % (number))
9 | hashing = hashlib.sha512(value.encode())
10 | if str(hashing.hexdigest()).upper() == encrypted:
11 | print("%05d" % (number))
12 | main()
13 |
--------------------------------------------------------------------------------
/Week14/CoinChangev1.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | money = int(input())
5 |
6 | _25coin, coin_left = divmod(money, 25)
7 | _10coin, coin_left = divmod(coin_left, 10)
8 | _5coin, _1coin = divmod(coin_left, 5)
9 |
10 | print(_25coin + _10coin + _5coin + _1coin)
11 | main()
12 |
--------------------------------------------------------------------------------
/Week14/Compound Interest.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | balance = int(input())
5 | load = float(input())
6 | year = int(input())
7 | for _ in range(year):
8 | balance += balance * load / 100
9 | print("%.2f" % balance)
10 | main()
11 |
--------------------------------------------------------------------------------
/Week14/EuclideanDistance.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def distance(point_1, point_2):
3 | """ Calculate the distance between two points """
4 | return ((point_1[0] - point_2[0])**2 + (point_1[1] - point_2[1])**2)**0.5
5 |
6 | def main():
7 | """ Main function """
8 | lst = []
9 | total = 0
10 | count = int(input())
11 | for _ in range(count):
12 | raw = input().split(" ")
13 | pos_x = int(raw[0])
14 | pos_y = int(raw[1])
15 | lst.append([pos_x, pos_y])
16 | for i in range(count - 1):
17 | total += distance(lst[i], lst[i + 1])
18 | print("%.2f" % total)
19 | main()
20 |
--------------------------------------------------------------------------------
/Week14/GCD_N.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | number_total = int(input())
5 | number_list = []
6 | for _ in range(number_total):
7 | number = int(input())
8 | number_list.append(number)
9 | max_number = max(number_list)
10 | gcd_value = 0
11 | for i in range(1, max_number+1):
12 | dividable = 0
13 | for number in number_list:
14 | if number % i == 0:
15 | dividable += 1
16 | if dividable == number_total:
17 | gcd_value = i
18 | print(gcd_value)
19 | main()
20 |
--------------------------------------------------------------------------------
/Week14/GasStation.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | goal = float(input())
5 | status = float(input())
6 | all_gas = [float(input()) for _ in range(int(input()))]
7 | count = 0
8 | remain = status
9 | if len(all_gas) != 0:
10 | all_gas += [all_gas[-1]]
11 | for i in range(len(all_gas) - 1):
12 | if all_gas[i] > remain:
13 | break
14 | elif (all_gas[i] < remain and all_gas[i + 1] <= remain) or all_gas[i] >= goal:
15 | pass
16 | else:
17 | count += 1
18 | remain = all_gas[i] + status
19 | print("depleted" if remain < goal else count)
20 | main()
21 |
--------------------------------------------------------------------------------
/Week14/Gram_v1.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | text = input()
5 | lis = []
6 | string_builder = ""
7 | value = -1
8 | for i in range(len(text)-1):
9 | lis.append(text[i]+text[i+1])
10 | for i in lis:
11 | if lis.count(i) > value:
12 | string_builder = i
13 | value = lis.count(i)
14 | print(string_builder)
15 | print(value)
16 | main()
17 |
--------------------------------------------------------------------------------
/Week14/HW_DotE.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import math
3 |
4 | def main():
5 | """ Main function """
6 | players = int(input())
7 | if players % 2 != 0:
8 | players += 1
9 | result = (math.factorial(players))/((math.factorial(players-(players//2))) \
10 | * (math.factorial(players//2)))
11 | print(int(result))
12 | main()
13 |
--------------------------------------------------------------------------------
/Week14/Island.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def flood_fill(i, j, row, col, island):
3 | """Return 1 if (i, j) and its neighbors are part of the island, 0 otherwise."""
4 | count = 0
5 | if island[i][j] == 1:
6 | island[i][j] = 2
7 | eight_directions = [(1, 0), (-1, 0), (0, 1), (0, -1), (1, 1), (1, -1), (-1, 1), (-1, -1)]
8 | new_positions = [(i+x, j+y) for x, y in eight_directions]
9 | for pos_x, pos_y in new_positions:
10 | if pos_x in range(0, row) and pos_y in range(0, col):
11 | flood_fill(pos_x, pos_y, row, col, island)
12 | count = 1
13 | return count
14 |
15 | def count_island(row, col, island):
16 | """Return total number of islands in the map."""
17 | count = 0
18 | for i in range(row):
19 | for j in range(col):
20 | count = count + flood_fill(i, j, row, col, island)
21 | return count
22 |
23 | def make_matrix():
24 | """Return number of rows, number of columns and matrix of island map."""
25 | row, col = [int(x) for x in input().split()]
26 | island = [[int(x) for x in input().split()] for _ in range(row)]
27 | return row, col, island
28 |
29 | def main():
30 | """ Main function """
31 | row, col, island = make_matrix()
32 | print(count_island(row, col, island))
33 | main()
34 |
--------------------------------------------------------------------------------
/Week14/MAZE RUNNER.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def dodamaze(maze, start, stop, path="", keep=None):
3 | """maze"""
4 | if keep == None:
5 | keep = []
6 | i, j = start
7 | if maze[i][j] == "Y":
8 | keep.append(path)
9 | checking = [(i-1, j, "E"), (i, j+1, "F"), (i+1, j, "G"), (i, j-1, "H")]
10 | checking = filter(lambda a: a[0] in range(10) and a[1] in range(20), checking)
11 | for k in filter(lambda a: maze[a[0]][a[1]] in " Y", checking):
12 | new = maze.copy()
13 | new[i] = new[i][:j] + "P" + new[i][j+1:]
14 | dodamaze(new, k[:2], stop, path + k[2], keep)
15 | return keep
16 | def main():
17 | """Maze"""
18 | maze = [input() for _ in range(10)]
19 | [start] = [(i, j) for i, row in enumerate(maze) for j, val in enumerate(row) if val == "X"]
20 | stop = [(i, j) for i, row in enumerate(maze) for j, val in enumerate(row) if val == "Y"]
21 | paths = []
22 | for i in stop:
23 | paths += sorted(dodamaze(maze, start, i))
24 | path = min(paths, key=len)
25 | for i, j in ("EU", "FR", "GD", "HL"):
26 | path = path.replace(i, j)
27 | print(path)
28 | print(len(path))
29 | print("You will make it on time!" if len(path)*23 < 10*60 else "You won't make it on time.")
30 | main()
31 |
--------------------------------------------------------------------------------
/Week14/Matrix_MN.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | lst = []
5 | row = int(input())
6 | column = int(input())
7 | for _ in range(row * column):
8 | lst.append(int(input()))
9 | for i in range(row):
10 | for j in range(column):
11 | print(lst[i * column + j], end=" ")
12 | print()
13 | main()
14 |
--------------------------------------------------------------------------------
/Week14/MultiplyMatrixPQR.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def addlistbyfewza(num1, num2, fewza007):
3 | """fewza007"""
4 | for _ in range(num1):
5 | lstf = []
6 | for _ in range(num2):
7 | few = int(input())
8 | lstf.append(few)
9 | fewza007.append(lstf)
10 | return fewza007
11 |
12 | def main():
13 | """ Main function """
14 | num1, num2, num3 = int(input()), int(input()), int(input())
15 | alst = addlistbyfewza(num1, num2, [])
16 | blst = addlistbyfewza(num2, num3, [])
17 | for i in alst:
18 | for j in range(len(blst[0])):
19 | sumbyfew, countfew = 0, 0;
20 | for k in i:
21 | sumbyfew += k * int(blst[countfew][j])
22 | countfew += 1
23 | print(sumbyfew, end=" ")
24 | print()
25 | main()
26 |
--------------------------------------------------------------------------------
/Week14/PairNumbering.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import json
3 |
4 | def main():
5 | """ Main function """
6 | dic1 = {}
7 | dic2 = {}
8 | txt1 = json.loads(input())
9 | txt2 = json.loads(input())
10 | for i in txt1:
11 | dic1[i] = dic1.get(i, 0)+1
12 | for i in txt2:
13 | dic2[i] = dic2.get(i, 0)+1
14 | num = int(input())
15 | ans = 0
16 | for i in sorted(dic1):
17 | if i > num:
18 | break
19 | if num-i in dic2:
20 | ans += (dic1[i] * dic2[num-i])
21 | print(ans)
22 | main()
23 |
--------------------------------------------------------------------------------
/Week14/Password.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 | import hashlib
4 |
5 | def main():
6 | """ Main function """
7 | password = input().encode('utf-8')
8 | hashed_password = hashlib.sha512(password).hexdigest().upper()
9 | print(hashed_password)
10 | main()
11 |
--------------------------------------------------------------------------------
/Week14/Phasmophobia.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | gho = {"EMF Level 5" : ['Banshee', 'Jinn', 'Oni', 'Phantom', 'Revenant', 'Shade']\
5 | , "Ghost Writing" : ['Demon', 'Oni', 'Revenant', 'Shade', 'Spirit', 'Yurei']\
6 | , "Fingerprints" : ['Banshee', 'Poltergeist', 'Revenant', 'Spirit', 'Wraith']\
7 | , "Spirit Box" : ['Demon', 'Jinn', 'Mare', 'Oni', 'Poltergeist', 'Spirit', 'Wraith']\
8 | , "Freezing Temperatures" : ['Banshee', 'Demon', 'Mare', 'Phantom', 'Wraith', 'Yurei']\
9 | , "Ghost Orb" : ['Jinn', 'Mare', 'Phantom', 'Poltergeist', 'Shade', 'Yurei']\
10 | , "No evidence" : ['Banshee', 'Jinn', 'Oni', 'Phantom', 'Revenant', 'Shade', 'Demon', \
11 | 'Mare', 'Poltergeist', 'Spirit', 'Wraith', 'Yurei']}
12 | value = list(set(gho[input()]).intersection(gho[input()]).intersection(gho[input()]))
13 | value.sort()
14 | if len(value) == 0:
15 | print("Not yet discovered")
16 | else:
17 | print(*value, sep="\n")
18 | main()
19 |
--------------------------------------------------------------------------------
/Week14/PongYa.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | count = input()
5 | if count[-1] == "3" or int(count) % 3 == 0:
6 | print("PONG")
7 | else:
8 | print(count)
9 | main()
10 |
--------------------------------------------------------------------------------
/Week14/PrasomSib.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | num = input()
5 | count = 0
6 | for i in range(len(num) - 1):
7 | total = 0
8 | for j in num[int(i):]:
9 | total += int(j)
10 | if total == 10:
11 | count += 1
12 | break
13 | print(count)
14 | main()
15 |
--------------------------------------------------------------------------------
/Week14/Rabbit.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import math
3 |
4 | def main(rabbit, stairs, carrot):
5 | """Rabbit"""
6 | few1, few2, few3 = 0, 0, 0
7 | if rabbit > carrot:
8 | few1, few2, few3 = int(rabbit-carrot), math.floor(stairs-((carrot/2)*(carrot+1))), 0
9 | if few1 <= -1 or few2 <= -1 or few3 <= -1:
10 | sud = math.floor((((2*stairs)+(1/4))**(1/2))-(1/2))
11 | few1, few2, few3 = int(
12 | rabbit-sud), math.floor(stairs-((sud/2)*(sud+1))), int(carrot-sud)
13 | elif ((rabbit/2)*(rabbit+1)) <= stairs:
14 | few1, few2, few3 = 0, math.floor(
15 | stairs-((rabbit/2)*(rabbit+1))), carrot-rabbit
16 | elif ((rabbit/2)*(rabbit+1)) > stairs:
17 | sud = math.floor((((2*stairs)+(1/4))**(1/2))-(1/2))
18 | few1, few2, few3 = int(
19 | rabbit-sud), math.floor(stairs-((sud/2)*(sud+1))), int(carrot-sud)
20 | if few1 == 0 and few2 == 0 and few3 == 0:
21 | print('Ahhahaha')
22 | else:
23 | print(few1, few2, few3)
24 |
25 | main(int(input()), int(input()), int(input()))
26 |
--------------------------------------------------------------------------------
/Week14/ScaledMatrix.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def scaled_maxtrix(value, count):
3 | """ Scaled maxtrix """
4 | return value[count] / max(value)
5 | def main():
6 | """ Main function """
7 | lst = []
8 | value = []
9 | row = int(input())
10 | column = int(input())
11 | for _ in range(row * column):
12 | lst.append(float(input()))
13 | absolved = abs(min(lst))
14 | for i in range(row * column):
15 | value.append(lst[i] + absolved)
16 | count = 0
17 | for _ in range(row):
18 | for _ in range(column):
19 | print("%.2f" % scaled_maxtrix(value, count), end=" ")
20 | count += 1
21 | print()
22 | main()
23 |
--------------------------------------------------------------------------------
/Week14/Scout.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | for _ in range(int(input())):
5 | lis1, lis2 = list(map(int, input().split())), sorted(list(map(int, input().split())))
6 | weight, egg = 0, 0
7 | for _ in range(lis1[0]):
8 | if weight + lis2[0] <= lis1[2] and egg < lis1[1]:
9 | weight += lis2[0]
10 | egg += 1
11 | lis2.pop(0)
12 | else:
13 | break
14 | print(egg)
15 | main()
16 |
--------------------------------------------------------------------------------
/Week14/Semi Prime.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def is_prime(num):
3 | """Return True if num is Prime number"""
4 | if num == 1:
5 | return False
6 | for i in range(2, int(num**0.5)+1):
7 | if num%i == 0:
8 | return False
9 | return True
10 |
11 | def main():
12 | """ Main function """
13 | amount = int(input())
14 | primes = []
15 | for num in range(1, amount+1):
16 | if is_prime(num):
17 | primes.append(num)
18 | value = 0
19 | for i in range(len(primes)):
20 | prime1 = primes[i]
21 | for prime2 in primes[i:]:
22 | if prime1*prime2 <= amount:
23 | value += 1
24 | print(value)
25 |
26 | main()
27 |
--------------------------------------------------------------------------------
/Week14/ShewaBowlar.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | num = int(input())
5 | coder = ""
6 | decoder = {"1":"papan", "2":"dogugu", "3":"gushigi", "4":"zugogo", "5":"zugagi", \
7 | "6":"gibugu", "7":"gezun", "8":"gegido", "9":"bagin", "+":"do ", "*":"gu ", "0":"zezeso"}
8 | group, new_group = [], []
9 | count = 0
10 | while num > 9:
11 | if num % 9 != 0:
12 | group.insert(0, str(num % 9))
13 | num -= num % 9
14 | num = num // 9
15 | count += 1
16 | group.insert(0, str(num))
17 | for i in range(len(group)):
18 | new_group.append("9*"*count+group[i])
19 | count -= 1
20 | encoder = "+".join(new_group).replace("*1", "")
21 | for i in encoder:
22 | coder += decoder[i]
23 | print(coder)
24 | main()
25 |
--------------------------------------------------------------------------------
/Week14/is_prime_LARGER.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main(num):
3 | """isPrime_large"""
4 | if num == 1:
5 | return "False"
6 | for i in range(2, int(num**0.5)+1, 3):
7 | if num % i == 0:
8 | return "False"
9 | return "True"
10 | print(main(int(input())))
11 |
--------------------------------------------------------------------------------
/Week15/Antenna.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import json
3 |
4 | def main():
5 | """ Main function """
6 | radius = int(input())
7 | people = sorted(json.loads(input()))
8 | limit = 0
9 | count = 1
10 | if not people:
11 | return print("0")
12 | limit = people.pop(0)+(radius*2)
13 | while people:
14 | new_people = people.pop(0)
15 | if new_people > limit:
16 | count += 1
17 | limit = new_people+radius*2
18 | print(count)
19 | main()
20 |
--------------------------------------------------------------------------------
/Week15/BishopMove.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | _ = int(input())
5 | _ = int(input())
6 | bis_row = int(input())
7 | bis_col = int(input())
8 | other_row = int(input())
9 | other_col = int(input())
10 | enemy = int(input())
11 | target_row = int(input())
12 | target_col = int(input())
13 |
14 | if abs(target_row - bis_row) == abs(target_col - bis_col):
15 | if target_row - bis_row < 0:
16 | step_row = -1
17 | else:
18 | step_row = 1
19 | if target_col - bis_col < 0:
20 | step_col = -1
21 | else:
22 | step_col = 1
23 |
24 | if target_row == other_row and target_col == other_col and enemy == 1:
25 | print("Yes")
26 | return
27 | if target_row == other_row and target_col == other_col and enemy == 0:
28 | print("No")
29 | return
30 | direction = []
31 |
32 | temp_row = bis_row
33 | temp_col = bis_col
34 | while temp_row != target_row and temp_col != target_col:
35 | direction.append((temp_row, temp_col))
36 | temp_row += step_row
37 | temp_col += step_col
38 | if (other_row, other_col) in direction:
39 | print("No")
40 | else:
41 | print("Yes")
42 | else:
43 | print("No")
44 | main()
45 |
--------------------------------------------------------------------------------
/Week15/BloodDonation.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def can_donation(age, weight, count_of_donations, checked):
3 | """ Can blood donation function """
4 | value = False
5 | if (age == 17 or 60 <= age <= 70) and checked == 'False':
6 | value = False
7 | elif (count_of_donations == 0 and age > 55) or age < 17 or age > 70 or weight < 45:
8 | value = False
9 | elif (age == 17 or 60 <= age <= 70) and checked == 'True' and weight >= 45:
10 | value = True
11 | elif 17 < age < 60 and weight >= 45:
12 | value = True
13 | return value
14 |
15 | def main():
16 | """ Main function """
17 | age = int(input())
18 | weight = int(input())
19 | count_of_donations = int(input())
20 | checked = False
21 | if age == 17 or 60 <= age <= 70:
22 | checked = input()
23 | result = can_donation(age, weight, count_of_donations, checked)
24 | if result:
25 | print("Yes")
26 | else:
27 | print("No")
28 | main()
29 |
--------------------------------------------------------------------------------
/Week15/BloodType.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def child(dad, mom, bloods):
3 | """ Find child bloodtype """
4 | if ("+" in dad+mom) == False:
5 | _ = [bloods.remove(i) for i in ["A+", "B+", "AB+", "O+"] if i in bloods]
6 | if ("A" in dad+mom) == False:
7 | _ = [bloods.remove(i) for i in ["A+", "A-", "AB+", "AB-"] if i in bloods]
8 | if ("B" in dad+mom) == False:
9 | _ = [bloods.remove(i) for i in ["B+", "B-", "AB+", "AB-"] if i in bloods]
10 | if ("AB" in dad+mom) == True:
11 | _ = [bloods.remove(i) for i in ["O+", "O-"] if i in bloods]
12 | if ("O" in dad+mom) == True:
13 | _ = [bloods.remove(i) for i in ["AB+", "AB-"] if i in bloods]
14 | return bloods
15 |
16 | def find_parent(parent, kid, bloods):
17 | """ Find missing parent """
18 | chances = [i for i in bloods if kid in child(parent, i, [i for i in bloods])]
19 | return "IMPOSSIBLE" if len(chances) == 0 else "{" + (" ".join(chances)) + "}"
20 |
21 | def main():
22 | """ Main function """
23 | dad, mom, kid = input().split()
24 | bloods = ["A+", "A-", "B+", "B-", "AB+", "AB-", "O+", "O-"]
25 |
26 | if kid == "?":
27 | print(dad, mom, "{" + (" ".join(child(dad, mom, [i for i in bloods]))) + "}")
28 | if mom == "?":
29 | print(dad, find_parent(dad, kid, [i for i in bloods]), kid)
30 | if dad == "?":
31 | print(find_parent(mom, kid, [i for i in bloods]), mom, kid)
32 | main()
33 |
--------------------------------------------------------------------------------
/Week15/Bowling.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def main():
5 | """ Calculate """
6 | inp = input().split()
7 |
8 | scores = []
9 | behavior = []
10 |
11 | frames = []
12 | while len(inp) != 0:
13 | score1 = int(inp.pop(0))
14 |
15 | if score1 == 10:
16 | scores.append(score1)
17 | behavior.append('Strike')
18 |
19 | frames.append('X')
20 | continue
21 |
22 | if len(inp) == 0:
23 | scores.append(score1)
24 | break
25 | score2 = int(inp.pop(0))
26 |
27 | if score1 + score2 == 10:
28 | scores.append(score1)
29 | scores.append(score2)
30 | behavior.append('Spare')
31 |
32 | frames.append(str(score1) if score1 != 0 else '-')
33 | frames.append('/')
34 | else:
35 | scores.append(score1)
36 | scores.append(score2)
37 | behavior.append('Normal')
38 |
39 | frames.append(str(score1) if score1 != 0 else '-')
40 | frames.append(str(score2) if score2 != 0 else '-')
41 |
42 | total_scores = []
43 | for i in range(len(behavior)):
44 | if i == 10:
45 | break
46 | if behavior[i] == 'Normal':
47 | prev_score = 0
48 | if len(total_scores) != 0:
49 | prev_score = total_scores[-1]
50 | total_scores.append(prev_score + scores.pop(0) + scores.pop(0))
51 | elif behavior[i] == 'Spare':
52 | prev_score = 0
53 | if len(total_scores) != 0:
54 | prev_score = total_scores[-1]
55 | score1 = scores.pop(0)
56 | score2 = scores.pop(0)
57 | score3 = 0
58 | if i == 9:
59 | score3 = scores.pop(0)
60 | extra_score = 0
61 | if len(scores) != 0:
62 | extra_score = scores[0]
63 | total_scores.append(prev_score + score1 +
64 | score2 + score3 + extra_score)
65 | elif behavior[i] == 'Strike':
66 | prev_score = 0
67 | if len(total_scores) != 0:
68 | prev_score = total_scores[-1]
69 | score = scores.pop(0)
70 | extra_score1 = 0
71 | extra_score2 = 0
72 | if len(scores) >= 1:
73 | extra_score1 = scores[0]
74 | if len(scores) >= 2:
75 | extra_score2 = scores[1]
76 | total_scores.append(prev_score + score +
77 | extra_score1 + extra_score2)
78 |
79 | total_scores = list(map(str, total_scores))
80 | print(' '.join(frames))
81 | print(' '.join(total_scores))
82 |
83 |
84 | main()
85 |
--------------------------------------------------------------------------------
/Week15/Dart.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | amount = int(input())
5 | count = 0
6 | for _ in range(amount):
7 | position = input()
8 | position = position.split(" ")
9 | point_x = int(position[0])
10 | point_y = int(position[1])
11 | radius = ((point_x**2)+(point_y**2))**0.5
12 | if radius <= 2:
13 | count += 5
14 | elif radius <= 4:
15 | count += 4
16 | elif radius <= 6:
17 | count += 3
18 | elif radius <= 8:
19 | count += 2
20 | elif radius <= 10:
21 | count += 1
22 | print(count)
23 | main()
24 |
--------------------------------------------------------------------------------
/Week15/Difference.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import json
3 |
4 | def main():
5 | """ Main function """
6 | lst_1 = json.loads(input())
7 | lst_2 = json.loads(input())
8 | set_1 = set(lst_1)
9 | set_2 = set(lst_2)
10 | check = set_1.union(set_2)
11 | count = 0
12 | for i in sorted(check):
13 | if abs(lst_1.count(i) - lst_2.count(i)) != 0:
14 | print(i, abs(lst_1.count(i) - lst_2.count(i)))
15 | count += 1
16 | if count == 0:
17 | print("ONAJI DAYO!")
18 | main()
19 |
--------------------------------------------------------------------------------
/Week15/Digit v2.py:
--------------------------------------------------------------------------------
1 | """ IG: few.pz """
2 | def main():
3 | """ Main function """
4 | word = input()
5 | if "thousand" in word:
6 | print(4)
7 | elif "hundred" in word:
8 | print(3)
9 | elif "ty" in word or "teen" in word or "ten" in word or "eleven" in word or "twelve" in word:
10 | print(2)
11 | else:
12 | print(1)
13 | main()
14 |
--------------------------------------------------------------------------------
/Week15/Discount.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | books = []
5 | while True:
6 | price = input()
7 | if price == "ENTER":
8 | break
9 | books.append(int(price))
10 | books.sort()
11 | if len(books) < 20:
12 | bonus = min(2, len(books) // 6)
13 | else:
14 | bonus = len(books) // 5
15 | print(sum(books[bonus:]))
16 | main()
17 |
--------------------------------------------------------------------------------
/Week15/Guess.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def check(sym, num, state):
3 | """ Check function """
4 | if state == 'YES':
5 | if sym == '<':
6 | return [i for i in range(int(num))]
7 | elif sym == '>':
8 | return [i for i in range(int(num)+1, 101)]
9 | elif sym == '=':
10 | return [int(num)]
11 | elif state == 'NO':
12 | if sym == '<':
13 | return [i for i in range(int(num), 101)]
14 | elif sym == '>':
15 | return [i for i in range(int(num)+1)]
16 | elif sym == '=':
17 | return [i for i in range(101) if int(num) != i]
18 |
19 | def main():
20 | """ Main function """
21 | ans = []
22 | while True:
23 | txt = input()
24 | if txt == 'END':
25 | break
26 | lst = txt.split()
27 | ans.append(check(lst[0], lst[1], lst[2]))
28 | if len(ans) > 0:
29 | set_a = set(ans[0])
30 | for i in range(1, len(ans)):
31 | set_a = set_a.intersection(set(ans[i]))
32 | print(*sorted(set_a))
33 | else:
34 | print(*range(101))
35 | main()
36 |
--------------------------------------------------------------------------------
/Week15/Heads and Legs.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | head = int(input())
5 | leg = int(input())
6 | rabbit, ghost = divmod(leg-2 * head, 2)
7 | bird = head - rabbit
8 | if rabbit >= 0 and bird >= 0 and ghost == 0:
9 | print(rabbit, bird)
10 | else:
11 | print("Impossible")
12 | main()
13 |
--------------------------------------------------------------------------------
/Week15/ISBN.py:
--------------------------------------------------------------------------------
1 | """ISBN"""
2 | def main():
3 | """ISBN"""
4 | id_card_text = input()
5 | id_card = [int(i) if i != "X" else 10 for i in id_card_text if i != "-"]
6 | sum_id_card = -sum(([i*j for i, j in zip(id_card[:-1], range(10, 1, -1))]))%11
7 | if sum_id_card == 10:
8 | sum_id_card = "X"
9 | if id_card_text[-1] == str(sum_id_card):
10 | print("Yes")
11 | else:
12 | print("No", sum_id_card)
13 |
14 | main()
15 |
--------------------------------------------------------------------------------
/Week15/Inverter.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | binary = input()
5 | string_builder = ""
6 | for bit in binary:
7 | if bit == "1":
8 | string_builder += "0"
9 | elif bit == "0":
10 | string_builder += "1"
11 | print(string_builder.lstrip("0"))
12 | main()
13 |
--------------------------------------------------------------------------------
/Week15/Kangaroo.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | kangaroo = [int(input()) for _ in range(3)]
5 | print(max(kangaroo[2] - kangaroo[1], kangaroo[1] - kangaroo[0]) - 1)
6 | main()
7 |
--------------------------------------------------------------------------------
/Week15/Kayak.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def closest(position):
3 | """ Keep position """
4 | num_min = position[1] - position[0]
5 | position_1 = 0
6 | position_2 = 1
7 | for i in range(len(position)-1):
8 | if position[i+1] - position[i] < num_min:
9 | num_min = position[i+1] - position[i]
10 | position_1 = i
11 | position_2 = i+1
12 | return num_min, position_1, position_2
13 |
14 | def main():
15 | """ Main function """
16 | number = int(input())
17 | weight = input().split()
18 | position = []
19 | num_min, position_1, position_2 = 0, 0, 0
20 | summation = 0
21 | for i in range(len(weight)):
22 | position.append(int(weight[i]))
23 | position.sort()
24 | for _ in range(number-1):
25 | num_min, position_1, position_2 = closest(position)
26 | summation += num_min
27 | position.remove(position[position_2])
28 | position.remove(position[position_1])
29 | print(summation)
30 |
31 | main()
32 |
--------------------------------------------------------------------------------
/Week15/MasterMind.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | answer = input()
5 | guess = input()
6 | point_b = 0
7 | point_w = 0
8 | point_b += sum([1 for i in range(4) if answer[i] == guess[i]])
9 | value = list(answer)
10 | for i in guess:
11 | if i in value:
12 | point_w += 1
13 | value.remove(i)
14 | point_w -= point_b
15 | word_b = "B" * point_b
16 | word_w = "W" * point_w
17 | word_zero = "O" * (4 - point_b - point_w)
18 | print(word_b + word_w + word_zero)
19 | main()
20 |
--------------------------------------------------------------------------------
/Week15/NumDays.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def add(month):
3 | """ Add days """
4 | manyday = 0
5 | for i in range(1, month):
6 | if i == 2:
7 | manyday += 28
8 | elif i == 4 or i == 6 or i == 9 or i == 11:
9 | manyday += 30
10 | else:
11 | manyday += 31
12 | return manyday
13 |
14 | def main():
15 | """ Main function """
16 | day1, mon1, day2, mon2 = int(input()), int(input()), int(input()), int(input())
17 | year = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
18 | if (day1 > year[mon1-1]) or (day2 > year[mon2-1]):
19 | print("Impossible")
20 | else:
21 | days1 = add(mon1)+day1
22 | days2 = add(mon2)+day2
23 | print(abs(days1-days2))
24 | main()
25 |
--------------------------------------------------------------------------------
/Week15/OTP.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | number = input()
5 | while number != '0':
6 | number_count = [number.count(str(i)) for i in range(10)]
7 | if len(number) == 4 and number_count.count(2) == 1:
8 | print("Valid")
9 | elif len(number) == 6 and (number_count.count(2) == 2 or number_count.count(3) == 1):
10 | print("Valid")
11 | elif len(number) == 8 and (number_count.count(2) == 3 or number_count.count(3) == 2):
12 | print("Valid")
13 | else:
14 | print("Invalid")
15 | number = input()
16 | main()
17 |
--------------------------------------------------------------------------------
/Week15/Perfect City.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import math
3 |
4 | def get_list(point_x):
5 | """ Get list function """
6 | value_1, value_2 = point_x
7 | if isinstance(value_1, float):
8 | return [(math.floor(value_1), value_2), (math.ceil(value_1), value_2)]
9 | else:
10 | return [(value_1, math.floor(value_2)), (value_1, math.ceil(value_2))]
11 |
12 | def distance(point_x, point_y):
13 | """ Distance function """
14 | value_1, value_2 = point_x
15 | value_3, value_4 = point_y
16 | value = abs(value_1 - value_3) + abs(value_2 - value_4)
17 | return value
18 |
19 | def main():
20 | """ Main function """
21 | point_x = float(input()), float(input())
22 | point_y = float(input()), float(input())
23 | calculate = min(distance(point_x, i) + distance(i, j) + distance(j, point_y) \
24 | for i in get_list(point_x) for j in get_list(point_y))
25 | print('%.2f' % calculate)
26 | main()
27 |
--------------------------------------------------------------------------------
/Week15/Reachability.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import json
3 | def run_node(node_map, node_parent, node_can_links):
4 | """elegant"""
5 | while node_parent:
6 | node_child = [i for i in node_map[node_parent.pop()] if i not in node_can_links]
7 | node_can_links += node_child
8 | node_parent += node_child
9 | return node_can_links
10 |
11 | def main():
12 | """ Main function """
13 | node_map = json.loads(input().replace("'", '"'))
14 | node_first = input()
15 | node_can_links = run_node(node_map, [node_first], [node_first])
16 | print(sorted(set(node_can_links)))
17 | main()
18 |
--------------------------------------------------------------------------------
/Week15/Refrigerator.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | total = int(input())
5 | valid = [int(valid) for valid in input().split()]
6 | value = 0
7 | valid.sort()
8 | while valid[0] != 0:
9 | for i in range(1, total):
10 | valid[i] = valid[i] - 1
11 | value += 1
12 | valid.sort()
13 | print(value)
14 | main()
15 |
--------------------------------------------------------------------------------
/Week15/TicTacToe.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | axis = []
5 | for _ in range(3):
6 | axis.append([i for i in input()])
7 | if (axis[0][0] == axis[1][1] == axis[2][2] and \
8 | axis[0][0] != '-' and axis[1][1] != '-' and axis[2][2] != '-')\
9 | or (axis[0][2] == axis[1][1] == axis[2][0] and axis[0][2] != '-' \
10 | and axis[1][1] != '-' and axis[2][0] != '-'):
11 | print(axis[1][1], "WIN")
12 | else:
13 | for j in range(3):
14 | if axis[0][j] == axis[1][j] == axis[2][j] and\
15 | (axis[0][j] != '-' and axis[1][j] != '-' and axis[2][j] != '-'):
16 | print(axis[0][j], "WIN")
17 | break
18 | elif axis[j][0] == axis[j][1] == axis[j][2] and\
19 | (axis[j][0] != '-' and axis[j][1] != '-' and axis[j][2] != '-'):
20 | print(axis[j][0], "WIN")
21 | break
22 | else:
23 | print("DRAW")
24 | main()
25 |
--------------------------------------------------------------------------------
/Week15/War.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import json
3 |
4 | def main():
5 | """ Main function """
6 | attack = sorted(json.loads(input()), reverse=True)
7 | deffend = sorted(json.loads(input()), reverse=True)
8 | defpin, att_pin, limit, value = 0, 0, len(deffend), 0
9 | while defpin != limit:
10 | if attack[att_pin] > deffend[defpin]:
11 | value += attack[att_pin]
12 | att_pin += 1
13 | defpin += 1
14 | print(value)
15 | main()
16 |
--------------------------------------------------------------------------------
/Week15/[Recomment] Fever.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | fever = float(input())
5 | if 36 <= fever < 38:
6 | print("No Fever")
7 | elif 38 <= fever < 39:
8 | print("Mild Fever")
9 | elif 39 <= fever < 40:
10 | print("High Fever")
11 | else:
12 | print("Very High Fever")
13 | main()
14 |
--------------------------------------------------------------------------------
/Week15/[Recomment] Temperature.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | temp = float(input())
5 | convert_from = input()
6 | convert_to = input()
7 |
8 | if convert_from == 'K':
9 | temp = temp - 273.15
10 | elif convert_from == 'F':
11 | temp = (temp - 32) * (5/9)
12 | elif convert_from == 'R':
13 | temp = (temp - 491.67) * (5/9)
14 | elif convert_from == 'C':
15 | temp = temp
16 |
17 | if convert_to == 'K':
18 | temp = temp + 273.15
19 | elif convert_to == 'F':
20 | temp = (temp * (9/5)) + 32
21 | elif convert_to == 'R':
22 | temp = (temp * (9/5)) + 491.67
23 | elif convert_to == 'C':
24 | temp = temp
25 | print("%.2f" % temp)
26 | main()
27 |
--------------------------------------------------------------------------------
/Week16/ATM.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def process_transaction(transaction, current_currency):
3 | """ Process Transaction """
4 | enum = transaction.split()
5 | if enum[0] == "D":
6 | current_currency += int(enum[1])
7 | elif enum[0] == "W":
8 | if current_currency >= int(enum[1]):
9 | current_currency -= int(enum[1])
10 | else:
11 | current_currency -= current_currency
12 | return current_currency
13 |
14 | def main():
15 | """ Main function """
16 | currency = 0
17 | currency = int(input())
18 | while True:
19 | transaction = input()
20 | if transaction == "END":
21 | break
22 | currency = process_transaction(transaction, currency)
23 | print(currency)
24 |
25 | main()
26 |
--------------------------------------------------------------------------------
/Week16/Area.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | row = int(input())
5 | count = ""
6 | for _ in range(row):
7 | area = input().replace(" ", "")
8 | count += area
9 | print(len(count))
10 | main()
11 |
--------------------------------------------------------------------------------
/Week16/Bus Seat.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | num1 = int(input())
5 | num2 = int(input())
6 | num3 = int(input())
7 | for i in range(num1, 0, -1):
8 | for j in range(i, (num1 * num2) + 1, num1):
9 | if j == num3:
10 | print("XX", end=" ")
11 | else:
12 | print("%0.2d" % (j), end=" ")
13 | if i % 2 != 0 and i != 1:
14 | print()
15 | print()
16 | main()
17 |
--------------------------------------------------------------------------------
/Week16/Colors.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def drawing_color(color_1, color_2):
3 | """ Drawing color function """
4 | color_lst = ['Red', 'Yellow', 'Blue']
5 | if color_1 not in color_lst or color_2 not in color_lst:
6 | print('Error')
7 | elif color_1 == color_2:
8 | print(color_1)
9 | elif (color_1 == 'Red' and color_2 == 'Yellow') or (color_2 == 'Red' and color_1 == 'Yellow'):
10 | print('Orange')
11 | elif (color_1 == 'Red' and color_2 == 'Blue') or (color_2 == 'Red' and color_1 == 'Blue'):
12 | print('Violet')
13 | elif (color_1 == 'Blue' and color_2 == 'Yellow') or (color_2 == 'Blue' and color_1 == 'Yellow'):
14 | print('Green')
15 |
16 | def main():
17 | """ Main function """
18 | primary_color = input()
19 | seconds_color = input()
20 | drawing_color(primary_color, seconds_color)
21 | main()
22 |
--------------------------------------------------------------------------------
/Week16/Coupon.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | price, coupon1, coupon2 = float(input()), input(), input()
5 | discount_1, mincost_1 = [float(i) for i in coupon1.split()]
6 | discount_2, mincost_2 = [float(i) for i in coupon2.split()]
7 | price_cp1 = price_cp2 = price
8 |
9 | if price >= mincost_1:
10 | price_cp1 = max(0, price - discount_1)
11 | if price >= mincost_2:
12 | price_cp2 = max(0, price*(100-discount_2)/100)
13 |
14 | if price_cp1 == price_cp2 == price:
15 | print("Nope")
16 | elif price_cp1 == price_cp2:
17 | print("1" if mincost_1 <= mincost_2 else "2", "%.1f" % price_cp1)
18 | elif price_cp1 < price_cp2:
19 | print("1 %.1f "% price_cp1)
20 | else:
21 | print("2 %.1f" % price_cp2)
22 | main()
23 |
--------------------------------------------------------------------------------
/Week16/Hamming.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | text = list(input())
5 | compare_text = list(input())
6 | count = 0
7 | for i in range(len(text)):
8 | if text[i] != compare_text[i]:
9 | count += 1
10 | print(count)
11 | main()
12 |
--------------------------------------------------------------------------------
/Week16/Hint.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def calculate_of_line(operator, line):
5 | """ Calculate of line """
6 | value = []
7 | if operator == "==":
8 | value.append(line)
9 | elif operator == "!=":
10 | value = [int(i) for i in range(0, 10) if i != line]
11 | elif operator == ">":
12 | value = [int(i) for i in range(0, 10) if i > line]
13 | elif operator == "<":
14 | value = [int(i) for i in range(0, 10) if i < line]
15 | elif operator == "<=":
16 | value = [int(i) for i in range(0, 10) if i <= line]
17 | elif operator == ">=":
18 | value = [int(i) for i in range(0, 10) if i >= line]
19 | return value
20 |
21 |
22 | def main():
23 | """ Main function """
24 | line_1 = input()
25 | line_2 = input()
26 | line_3 = input()
27 |
28 | operator_line_1 = line_1.split()[0]
29 | operator_line_2 = line_2.split()[0]
30 | operator_line_3 = line_3.split()[0]
31 |
32 | value_line1 = calculate_of_line(operator_line_1, int(line_1.split()[1]))
33 | value_line2 = calculate_of_line(operator_line_2, int(line_2.split()[1]))
34 | value_line3 = calculate_of_line(operator_line_3, int(line_3.split()[1]))
35 |
36 | for axis_line3 in value_line3:
37 | for axis_line2 in value_line2:
38 | for axis_line1 in value_line1:
39 | print(str(axis_line3) + str(axis_line2) + str(axis_line1))
40 |
41 |
42 | main()
43 |
--------------------------------------------------------------------------------
/Week16/IP Address.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | text = input().split('.')
5 | if len(text) != 4:
6 | print('Invalid IPv4 address')
7 | return
8 | for i in text:
9 | for j in i:
10 | if not j.isnumeric():
11 | print('Invalid IPv4 address')
12 | return
13 | if int(i) > 255 or int(i) < 0:
14 | print('Invalid IPv4 address')
15 | return
16 | print(*[int(i) for i in text], sep='.')
17 | main()
18 |
19 |
--------------------------------------------------------------------------------
/Week16/Lucky Number.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def main(number):
5 | """ Main function """
6 | number1 = range(-1, number+1, 2)
7 | i = 2
8 | while number1[i:]:
9 | number1 = sorted(set(number1) - set(number1[number1[i]::number1[i]]))
10 | i += 1
11 | print(*(number1[1:number+1]), sep=(' '))
12 |
13 |
14 | main(int(input()))
15 |
--------------------------------------------------------------------------------
/Week16/Majority.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | _, vote, most_vote, most_free, list_score = int(input()), int(input()), '', 0, []
5 | for _ in range(vote):
6 | each_vote = int(input())
7 | list_score.append(each_vote)
8 | if list_score.count(each_vote) > most_free:
9 | most_free = list_score.count(each_vote)
10 | most_vote = each_vote
11 | if most_free > (vote/2):
12 | print(most_vote, most_free)
13 | else:
14 | print('0', most_free)
15 | main()
16 |
--------------------------------------------------------------------------------
/Week16/Mickey.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | mickey_home = int(input())
5 | list_mickey = []
6 | list_home = []
7 | list_max = []
8 | for _ in range(mickey_home):
9 | mickey = int(input())
10 | list_mickey.append(mickey)
11 | for _ in range(mickey_home):
12 | home = int(input())
13 | list_home.append(home)
14 | list_mickey.sort()
15 | list_home.sort()
16 | for i in range(mickey_home):
17 | value_max = (abs(int(list_mickey[i])-int(list_home[i])))
18 | list_max.append(value_max)
19 | print(max(list_max))
20 | main()
21 |
--------------------------------------------------------------------------------
/Week16/Milk v2.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | price = float(input())
5 | lid_ex = int(input())
6 | lid_ex_milk = int(input())
7 | bottle_ex = int(input())
8 | bottle_ex_milk = int(input())
9 | money = float(input())
10 |
11 | buy = money // price
12 | total_milk = lid = bottle = buy
13 | while lid >= lid_ex or bottle >= bottle_ex:
14 | milk_from_lid = (lid // lid_ex) * lid_ex_milk
15 | milk_from_bottle = (bottle // bottle_ex) * bottle_ex_milk
16 | get_milk = milk_from_lid + milk_from_bottle
17 | lid = get_milk + lid % lid_ex
18 | bottle = get_milk + bottle % bottle_ex
19 | total_milk += get_milk
20 | print(int(total_milk))
21 | main()
22 |
--------------------------------------------------------------------------------
/Week16/Pad Thai.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def main():
5 | """ Main function """
6 | check_item = ["Pad Thai Sauce", "Tofu", "Pickle Turnip", "Shrimp",
7 | "Bean Sprouts", "Noodle", "Chives", "Lime", "Egg", "Oil", "Peanuts"]
8 | check_taste = ["Sweet", "Sour", "Salty"]
9 | item_list = []
10 | taste_list = []
11 | not_in_check = []
12 | while True:
13 | item = input()
14 | if item == "Cook":
15 | break
16 | if item not in item_list:
17 | item_list.append(item)
18 | if item not in check_item:
19 | not_in_check.append(item)
20 | while True:
21 | taste = input()
22 | if taste == "End":
23 | break
24 | if taste not in taste_list:
25 | taste_list.append(taste)
26 | if not_in_check != []:
27 | print("This is not Pad Thai!!!")
28 | elif item_list != check_item:
29 | print("This is bad!")
30 | elif item_list == check_item:
31 | if taste_list == check_taste:
32 | print("Delicious!")
33 | else:
34 | print("Not Bad...")
35 |
36 |
37 | main()
38 |
--------------------------------------------------------------------------------
/Week16/Pro.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | promotion = int(input())
5 | must_paid = int(input())
6 | standard_price = int(input())
7 | people = int(input())
8 |
9 | price = (people // promotion) * must_paid * standard_price
10 | price += (people % promotion) * standard_price
11 | print(price)
12 | main()
13 |
--------------------------------------------------------------------------------
/Week16/RunGame.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | line = input().split()
5 | value = 0
6 | keep_items = 0
7 | for i in line:
8 | changed_value = int(i)
9 | value = abs(changed_value - value)
10 | keep_items += value
11 | value = changed_value
12 | print(keep_items)
13 | main()
14 |
--------------------------------------------------------------------------------
/Week16/Sort.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def merge_value(value):
5 | """ Merge Sorted by some where """
6 | if len(value) > 1:
7 | mid = len(value) // 2
8 | left = value[:mid]
9 | right = value[mid:]
10 | # Recursive call on each half
11 | merge_value(left)
12 | merge_value(right)
13 | # Two iterators for traversing the two halves
14 | i = 0
15 | j = 0
16 | # Iterator for the main list
17 | k = 0
18 | while i < len(left) and j < len(right):
19 | if left[i] <= right[j]:
20 | # The value from the left half has been used
21 | value[k] = left[i]
22 | # Move the iterator forward
23 | i += 1
24 | else:
25 | value[k] = right[j]
26 | j += 1
27 | # Move to the next slot
28 | k += 1
29 | # For all the remaining values
30 | while i < len(left):
31 | value[k] = left[i]
32 | i += 1
33 | k += 1
34 | while j < len(right):
35 | value[k] = right[j]
36 | j += 1
37 | k += 1
38 |
39 |
40 | def main():
41 | """ Main function """
42 | value = []
43 | while True:
44 | raw = input()
45 | if raw == "END":
46 | break
47 | value.append(int(raw))
48 | merge_value(value)
49 | for i in value:
50 | print(i)
51 |
52 |
53 | main()
54 |
--------------------------------------------------------------------------------
/Week16/T-score.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def main():
5 | """ Main function """
6 | amount = int(input())
7 | int(input())
8 | value = 0
9 | value_with_power_2 = 0
10 | list_score = []
11 | for _ in range(amount):
12 | score_student = int(input())
13 | value += score_student
14 | value_with_power_2 += (score_student**2)
15 | list_score.append(score_student)
16 | standard_deviation = (
17 | ((amount*(value_with_power_2))-(value**2))/(amount*(amount-1)))**0.5
18 | sum_x = value/amount
19 | for i in list_score:
20 | sum_z = (int(i)-sum_x) / standard_deviation
21 | print('%.2f' % (50 + 10*(sum_z)))
22 |
23 |
24 | main()
25 |
--------------------------------------------------------------------------------
/Week16/WPM.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def main():
5 | """ Main function """
6 | name, num = input(), int(input())
7 | if (name == "Kids" and num < 11) or (name == "Adults" and num < 26):
8 | print("Very Slow")
9 | elif name == "Kids":
10 | if 11 <= num <= 20:
11 | print("Slow")
12 | elif num <= 30:
13 | print("Average")
14 | elif num <= 40:
15 | print("Fast")
16 | else:
17 | print("Very Fast")
18 | elif name == "Adults":
19 | if 26 <= num <= 35:
20 | print("Slow/Beginner")
21 | elif num <= 45:
22 | print("Intermediate/Average")
23 | elif num <= 65:
24 | print("Fast/Advanced")
25 | elif num <= 80:
26 | print("Very Fast")
27 | else:
28 | print("Insane")
29 |
30 |
31 | main()
32 |
--------------------------------------------------------------------------------
/Week16/[Recomment] Tax.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | yearly = int(input())
5 | ccc = int(input())
6 | value_2 = 0
7 | value_1 = 0
8 | if ccc <= 600:
9 | value_2 += ((ccc) * 0.5)
10 | elif ccc <= 1800:
11 | value_2 += ((ccc - 600) * 1.50) + 300
12 | elif ccc > 1800:
13 | value_2 += ((ccc - 1800) * 4) + 2100
14 | if yearly == 6:
15 | value_1 = value_2 * 0.9
16 | elif yearly == 7:
17 | value_1 = value_2 * 0.8
18 | elif yearly == 8:
19 | value_1 = value_2 * 0.7
20 | elif yearly == 9:
21 | value_1 = value_2 * 0.6
22 | elif yearly >= 10:
23 | value_1 = value_2 * 0.5
24 | if yearly <= 5:
25 | print("%.2f " % value_2)
26 | elif yearly >= 6:
27 | print("%.2f" % value_1)
28 | main()
29 |
--------------------------------------------------------------------------------
/Week16/iPad Air.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def main():
5 | """ Main function """
6 | color_lst = ['Space Gray', 'Silver', 'Green', 'Rose Gold', 'Sky Blue']
7 | disk_lst = ['64 GB', '256 GB']
8 | connection_lst = ['Wi-Fi', 'Wi-Fi + Cellular']
9 |
10 | color = input()
11 | disk = input()
12 | connection = input()
13 |
14 | disk += ' GB'
15 |
16 | if color not in color_lst or disk not in disk_lst or connection not in connection_lst:
17 | print('Not Available')
18 | else:
19 | if disk == "64 GB":
20 | if connection == "Wi-Fi":
21 | print(19900)
22 | else:
23 | print(24400)
24 | elif disk == "256 GB":
25 | if connection == "Wi-Fi":
26 | print(24900)
27 | else:
28 | print(29400)
29 |
30 |
31 | main()
32 |
--------------------------------------------------------------------------------
/Week3/Boomerang.py:
--------------------------------------------------------------------------------
1 | """IG: fewpz"""
2 |
3 | def main():
4 | """Main functions"""
5 | x_val = int(input())
6 | y_val = int(input())
7 | z_val = int(input())
8 |
9 | print(x_val + 1)
10 | print(str((7*y_val**3) + (2*y_val**2) - (31*y_val) + 1))
11 | print(str(-z_val))
12 | print(str((x_val + y_val) * (x_val - y_val)))
13 | print(str((y_val - ((y_val**2) - (4*x_val*z_val))**0.5) / (2 * x_val)))
14 |
15 |
16 | main()
17 |
--------------------------------------------------------------------------------
/Week3/Entryway.py:
--------------------------------------------------------------------------------
1 | """IG: fewpz"""
2 |
3 |
4 | def main():
5 | """Main functions"""
6 | print("Output")
7 |
8 |
9 | main()
--------------------------------------------------------------------------------
/Week3/F2C.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def main():
5 | """Main functions"""
6 | value = float(input())
7 | celsius = 5/9 * (value-32)
8 |
9 | print("%.1f Celsius" % celsius)
10 |
11 |
12 | main()
--------------------------------------------------------------------------------
/Week3/FollowTheLead.py:
--------------------------------------------------------------------------------
1 | """IG: fewpz"""
2 | import math
3 |
4 |
5 | def main():
6 | """Main functions"""
7 | print(1+2+3+4+5+6+7+8+9+10)
8 | print(10-9-8-7-6-5-4-3-2-1)
9 | print(1+1+1+1+1+1+1+1+1*0+1+1)
10 | print(1*2+3*4)
11 | print(11+22-33*44/55)
12 | print((7+2-3)*4)
13 | print((42-11)*(7*2+(4**7)))
14 | print((3*((9**2)+(2)*(5)-10))/(2*7))
15 | print(((7-1)/(2+4))*(10/51))
16 | print(((4000*(50**4)*87)+(4000*5))/(math.sqrt(((72-111)**2)+((10-314)**2))))
17 |
18 |
19 | main()
--------------------------------------------------------------------------------
/Week3/Gift I.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def main():
5 | """Main functions"""
6 | x_val = float(input())
7 | y_val = float(input())
8 |
9 | x_total = x_val * 2
10 | total = x_total - y_val
11 |
12 | print(total)
13 |
14 |
15 | main()
--------------------------------------------------------------------------------
/Week3/JumpAround.py:
--------------------------------------------------------------------------------
1 | """IG: fewpz"""
2 |
3 |
4 | def main():
5 | """Main functions"""
6 | value = int(input())
7 | print(value)
8 | print(value+5)
9 | print(value-17)
10 | print(value*32)
11 | print(5*value**2 + (10*5) * value + 3)
12 |
13 |
14 | main()
--------------------------------------------------------------------------------
/Week3/Jumping.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def print_output(num):
5 | """Print output functions"""
6 | print("Output%d" % num)
7 | print("Output%d" % num)
8 | print("Output%d" % num)
9 |
10 |
11 | def jumping():
12 | """Jumping functions"""
13 | print_output(1)
14 | print_output(2)
15 | print_output(3)
16 | print_output(4)
17 |
18 |
19 | def main():
20 | """Main functions"""
21 | jumping()
22 |
23 |
24 | main()
--------------------------------------------------------------------------------
/Week3/MoreEntryway.py:
--------------------------------------------------------------------------------
1 | """IG: fewpz"""
2 |
3 |
4 | def main():
5 | """Main functions"""
6 | for i in range(1, 21):
7 | print("Output_%d" % i)
8 |
9 |
10 | main()
--------------------------------------------------------------------------------
/Week3/MyMath.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | import math
3 |
4 |
5 | def kareen_five():
6 | """Kareen five functions"""
7 | head = math.log(4234, 5) + math.log(8191, 2) + 71 * math.log(156154, 10)
8 | body = math.log(777, 7) - math.log(888, 8) - math.log(999, 9)
9 | print(head/body)
10 |
11 |
12 | def kareen_four():
13 | """Kareen four functions"""
14 | head = math.log(1234**4, 10)
15 | print(head)
16 |
17 |
18 | def kareen_there():
19 | """Kareen there functions"""
20 | head = 15 + 25
21 | body = math.sqrt((25-12)**2 + (12-15)**2)
22 |
23 | print(head/body)
24 |
25 |
26 | def kareen_two():
27 | """Kareen two functions"""
28 | head = math.factorial(16) * math.factorial(4)
29 | body = math.factorial(8)
30 |
31 | total = head/body
32 | print(total)
33 |
34 |
35 | def kareen_one():
36 | """Kareen one functions"""
37 | head = math.sin(math.radians(90)) + math.sin(math.radians(60))**2
38 | body = math.cos(math.radians(245**2)) + math.cos(math.radians(45 + 135))
39 |
40 | total = head/body
41 | print(total)
42 |
43 |
44 | def main():
45 | """Main functions"""
46 | kareen_one()
47 | kareen_two()
48 | kareen_there()
49 | kareen_four()
50 | kareen_five()
51 |
52 |
53 | main()
--------------------------------------------------------------------------------
/Week3/Rectangle.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def main():
5 | """Main functions"""
6 | x_val = int(input())
7 | y_val = int(input())
8 |
9 | print(x_val * y_val)
10 | print(((x_val + y_val) + (x_val + y_val)))
11 |
12 |
13 | main()
--------------------------------------------------------------------------------
/Week3/Regulation.py:
--------------------------------------------------------------------------------
1 | """IG: fewpz"""
2 |
3 |
4 | def main():
5 | """Main functions"""
6 | x_val = int(input())
7 | y_val = float(input())
8 | z_val = input()
9 |
10 | print(("%d" % x_val).rjust(30, " "))
11 | print(("%030d" % x_val))
12 | print("%.2f" % y_val)
13 | print("%.12f" % y_val)
14 | print("%40s" % z_val)
15 |
16 |
17 | main()
--------------------------------------------------------------------------------
/Week3/SaveComputeRepeat.py:
--------------------------------------------------------------------------------
1 | """IG: fewpz"""
2 |
3 |
4 | def main():
5 | """Main functions"""
6 | start_here = 492137954293754252786
7 | millseconds = start_here
8 | seconds = millseconds // 1000
9 | millseconds = millseconds % 1000
10 | minutes = seconds // 60
11 | seconds = seconds % 60
12 | hours = minutes // 60
13 | minutes = minutes % 60
14 | days = hours // 24
15 | hours = hours % 24
16 |
17 | print("%d %d %d %d %d" % (days, hours, minutes, seconds, millseconds))
18 |
19 | main()
--------------------------------------------------------------------------------
/Week3/StillJumping.py:
--------------------------------------------------------------------------------
1 | """IG: fewpz"""
2 |
3 |
4 | def main():
5 | """Main functions"""
6 | value = input()
7 | print(value)
8 |
9 |
10 | main()
--------------------------------------------------------------------------------
/Week3/Timing.py:
--------------------------------------------------------------------------------
1 | """IG: fewpz"""
2 |
3 |
4 | def main():
5 | """Main functions"""
6 | time = int(input())
7 |
8 | day = time // (24 * 3600)
9 | time = time % (24 * 3600)
10 | hour = time // 3600
11 | time %= 3600
12 | minutes = time // 60
13 | time %= 60
14 | seconds = time
15 |
16 | print(day, hour, minutes, seconds)
17 |
18 |
19 | main()
--------------------------------------------------------------------------------
/Week3/Train.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def main():
5 | """Main functions"""
6 | x_val = (input())
7 | y_val = (input())
8 | z_val = int(input())
9 |
10 | total = x_val + y_val
11 | print(total)
12 | print((total)*z_val)
13 |
14 |
15 | main()
--------------------------------------------------------------------------------
/Week4/BMI.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def calc_body_mass_index(weight, hight):
5 | """Calculate body mass index"""
6 | bmi = weight/(hight/100)**2
7 | return bmi
8 |
9 |
10 | def main():
11 | """Main function"""
12 | player_1 = input()
13 | player_1_height = float(input())
14 | player_1_weight = float(input())
15 | player_2 = input()
16 | player_2_height = float(input())
17 | player_2_weight = float(input())
18 | player_3 = input()
19 | player_3_height = float(input())
20 | player_3_weight = float(input())
21 | player_4 = input()
22 | player_4_height = float(input())
23 | player_4_weight = float(input())
24 | player_5 = input()
25 | player_5_height = float(input())
26 | player_5_weight = float(input())
27 |
28 | print("%s's BMI = %.2f" %
29 | (player_1, (calc_body_mass_index(player_1_height, player_1_weight))))
30 | print("%s's BMI = %.2f" %
31 | (player_2, (calc_body_mass_index(player_2_height, player_2_weight))))
32 | print("%s's BMI = %.2f" %
33 | (player_3, (calc_body_mass_index(player_3_height, player_3_weight))))
34 | print("%s's BMI = %.2f" %
35 | (player_4, (calc_body_mass_index(player_4_height, player_4_weight))))
36 | print("%s's BMI = %.2f" %
37 | (player_5, (calc_body_mass_index(player_5_height, player_5_weight))))
38 |
39 |
40 | main()
41 |
--------------------------------------------------------------------------------
/Week4/BMIAgain.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | weight = float(input())
5 | height = float(input())
6 |
7 | bmi = weight/(height/100)**2
8 |
9 | value = ""
10 | if bmi < 18.5:
11 | value = "Underweight"
12 | elif bmi < 25:
13 | value = "Normal"
14 | elif bmi < 30:
15 | value = "Overweight"
16 | elif bmi >= 30:
17 | value = "Obese"
18 | print(value)
19 |
20 | main()
21 |
--------------------------------------------------------------------------------
/Week4/CompositeFunction.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def x_func(value):
5 | """Functions fog"""
6 | return 2*value
7 |
8 |
9 | def g_func(value):
10 | """Functions gof"""
11 | return (value/2) + 1
12 |
13 |
14 | def main():
15 | """Main function"""
16 | value = int(input())
17 | print("%.2f" % (x_func(g_func(value))))
18 | print("%.2f" % (g_func(x_func(value))))
19 |
20 |
21 | main()
22 |
--------------------------------------------------------------------------------
/Week4/DataSpike.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def compare_integer(var_a, var_b):
3 | """Find the maximum value"""
4 | if var_a >= var_b:
5 | return var_a
6 | else:
7 | return var_b
8 |
9 | def main():
10 | """Main function"""
11 | x_val = int(input())
12 | y_val = int(input())
13 |
14 | total = compare_integer(x_val, y_val)
15 | z_val = int(input())
16 | total = compare_integer(total, z_val)
17 | z_val = int(input())
18 | total = compare_integer(total, z_val)
19 | z_val = int(input())
20 | total = compare_integer(total, z_val)
21 | z_val = int(input())
22 | total = compare_integer(total, z_val)
23 | z_val = int(input())
24 | total = compare_integer(total, z_val)
25 | z_val = int(input())
26 | total = compare_integer(total, z_val)
27 | print(total)
28 | main()
29 |
--------------------------------------------------------------------------------
/Week4/Distinguish.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def main():
5 | """Main function"""
6 | x_val = int(input())
7 | if x_val > 180:
8 | print("You're hit the door edge.")
9 | else:
10 | print("Nothing happens.")
11 |
12 |
13 | main()
14 |
--------------------------------------------------------------------------------
/Week4/EuclideanDistance2D.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | val_a = float(input())
5 | val_b = float(input())
6 | val_c = float(input())
7 | val_d = float(input())
8 |
9 | print((((val_a-val_c)**2)+((val_b-val_d)**2))**0.5)
10 |
11 |
12 | main()
13 |
--------------------------------------------------------------------------------
/Week4/FoodGrade I.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def find_wing_chicken():
3 | """Find the wing chicken"""
4 | wing = int(input())
5 | if 50 <= wing <= 70:
6 | return wing
7 | else:
8 | return 0
9 |
10 | def main():
11 | """Main function"""
12 | x_val = list()
13 | x_val.append(find_wing_chicken())
14 | x_val.append(find_wing_chicken())
15 | x_val.append(find_wing_chicken())
16 | x_val.append(find_wing_chicken())
17 | x_val.append(find_wing_chicken())
18 | x_val.append(find_wing_chicken())
19 | x_val.append(find_wing_chicken())
20 | x_val.append(find_wing_chicken())
21 | x_val.append(find_wing_chicken())
22 | x_val.append(find_wing_chicken())
23 | x_val.append(find_wing_chicken())
24 | x_val.append(find_wing_chicken())
25 | x_val.append(find_wing_chicken())
26 | x_val.append(find_wing_chicken())
27 | x_val.append(find_wing_chicken())
28 | x_val.append(find_wing_chicken())
29 | x_val.append(find_wing_chicken())
30 | x_val.append(find_wing_chicken())
31 | x_val.append(find_wing_chicken())
32 | x_val.append(find_wing_chicken())
33 | x_val.append(find_wing_chicken())
34 | x_val.append(find_wing_chicken())
35 | x_val.append(find_wing_chicken())
36 | x_val.append(find_wing_chicken())
37 |
38 | value = len(x_val) - x_val.count(0)
39 | print(value)
40 | main()
41 |
--------------------------------------------------------------------------------
/Week4/Gift II.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def is_even(x_val):
3 | """check is odd right functions"""
4 | if (x_val % 2) == 0:
5 | print(x_val)
6 | else:
7 | return False
8 |
9 | def main():
10 | """Main function"""
11 | x_val = int(input())
12 | is_even(x_val)
13 | x_val = int(input())
14 | is_even(x_val)
15 | x_val = int(input())
16 | is_even(x_val)
17 | x_val = int(input())
18 | is_even(x_val)
19 | x_val = int(input())
20 | is_even(x_val)
21 | x_val = int(input())
22 | is_even(x_val)
23 | x_val = int(input())
24 | is_even(x_val)
25 | x_val = int(input())
26 | is_even(x_val)
27 |
28 | main()
29 |
--------------------------------------------------------------------------------
/Week4/Grade I.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def main():
5 | """Main function"""
6 | x_val = float(input())
7 | if x_val >= 60:
8 | print("Pass")
9 | else:
10 | print("Fail")
11 |
12 |
13 | main()
14 |
--------------------------------------------------------------------------------
/Week4/Grade II.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def convert_text(value):
3 | """Covert text to grade"""
4 | text = "ERR"
5 | if value >= 95 and value <= 100:
6 | text = "A"
7 | elif value >= 90 and value < 95:
8 | text = "B+"
9 | elif value >= 85 and value < 90:
10 | text = "B"
11 | elif value >= 80 and value < 85:
12 | text = "C+"
13 | elif value >= 75 and value < 80:
14 | text = "C"
15 | elif value >= 70 and value < 75:
16 | text = "D+"
17 | elif value >= 65 and value < 70:
18 | text = "D"
19 | elif value >= 60 and value < 65:
20 | text = "F+"
21 | elif value > 0 and value < 60:
22 | text = "F"
23 | elif value < 0 or value > 100:
24 | text = "ERR"
25 |
26 | return text
27 |
28 | def main():
29 | """Main function"""
30 | score = float(input())
31 | print(convert_text(score))
32 | main()
33 |
--------------------------------------------------------------------------------
/Week4/ODD_EVEN.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def is_odd(x_val):
3 | """Check is odd function"""
4 | if (x_val % 2) == 0:
5 | return "False"
6 | else:
7 | return "True"
8 |
9 | def main():
10 | """Main function"""
11 | print(is_odd(int(input())))
12 |
13 |
14 | main()
15 |
--------------------------------------------------------------------------------
/Week4/PlanB.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | x_val = float(input())
5 | if x_val >= 450:
6 | print("Pass")
7 | else:
8 | print("Fail")
9 | print("Process is terminated")
10 |
11 | main()
12 |
--------------------------------------------------------------------------------
/Week4/PointInCircle.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | x_val = float(input())
5 | y_val = float(input())
6 | radius = float(input())
7 | circle_x = float(input())
8 | circle_y = float(input())
9 |
10 | if ((x_val - circle_x)**2) + ((y_val - circle_y)**2) <= radius**2:
11 | print("True")
12 | else:
13 | print("False")
14 | main()
15 |
--------------------------------------------------------------------------------
/Week4/Quadrant.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def main():
5 | """Main function"""
6 | x_val = int(input())
7 | y_val = int(input())
8 | if x_val > 0 and y_val > 0:
9 | print("Q1")
10 | elif x_val > 0 and y_val < 0:
11 | print("Q4")
12 | elif x_val < 0 and y_val > 0:
13 | print("Q2")
14 | elif x_val < 0 and y_val < 0:
15 | print("Q3")
16 | elif y_val == 0 and x_val != 0:
17 | print("X")
18 | elif x_val == 0 and y_val != 0:
19 | print("Y")
20 | elif x_val == 0 and y_val == 0:
21 | print("O")
22 |
23 |
24 | main()
25 |
--------------------------------------------------------------------------------
/Week4/Ratatype.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def print_here(x_val):
3 | """Get string of text in value"""
4 | if x_val == 1:
5 | return "In Deep Learning, a Convolutional Neural Network (CNN) is a class \
6 | of Deep Neural Networks, most commonly applied to analyzing visual imagery."
7 | if x_val == 2:
8 | return '"Two things are infinite: the universe and human stupidity; \
9 | and I\'m not sure about the universe". - Albert Einstein'
10 | if x_val == 3:
11 | return "Statistics is the discipline that concerns the collection, \
12 | organization, displaying, analysis, interpretation and presentation of data."
13 | if x_val == 4:
14 | return 'The backslash (\\) is a typographical mark used mainly in computing \
15 | and is the mirror image of the common slash (/). It is sometimes called "escape character".'
16 |
17 | def main():
18 | """Main function"""
19 | x_val = int(input())
20 | print(print_here(x_val))
21 |
22 | main()
23 |
--------------------------------------------------------------------------------
/Week4/Robot I.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def main():
5 | """Main function"""
6 | name = input()
7 | x_val = float(input())
8 | if x_val < 18:
9 | print("%s, you can pass." % name)
10 | elif x_val >= 18:
11 | print("%s, you shall not pass." % name)
12 |
13 |
14 | main()
15 |
--------------------------------------------------------------------------------
/Week4/Seven.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = int(input())
5 | if value % 4 == 1:
6 | print("7")
7 | elif value % 4 == 2:
8 | print("9")
9 | elif value % 4 == 3:
10 | print("3")
11 | elif value % 4 == 0:
12 | print("1")
13 | main()
14 |
--------------------------------------------------------------------------------
/Week4/Squareroot.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | x_val = pow(int(input()), 2)
5 | y_val = int(input())
6 |
7 | if x_val == y_val:
8 | print("True")
9 | else:
10 | print("False")
11 |
12 | main()
13 |
--------------------------------------------------------------------------------
/Week4/TheFunctionWithin.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def fun_x(val_x):
5 | """ f(x) = 2x """
6 | return 2 * val_x
7 |
8 |
9 | def gun_x(val_x):
10 | """ g(x) = 3x^4 - x^3 + 2x^2 + 10 """
11 | return (3*pow(val_x, 4)) - pow(val_x, 3) + (2*pow(val_x, 2)) + 10
12 |
13 |
14 | def hun_x(val_x, val_y, val_z):
15 | """ h(x, y, z) = (z + x)^2 - xy + y^2 """
16 | return pow(val_z+val_x, 2) - (val_x*val_y) + pow(val_y, 2)
17 |
18 |
19 | def iun_x(val_a, val_b, val_c, val_d):
20 | """ i(a, b, c, d) = (a^2 + b^2 - c^2) / (d^2 - 2ad + 2a) """
21 | num = pow(val_a, 2) + pow(val_b, 2) - pow(val_c, 2)
22 | den = pow(val_d, 2) - (2*val_a*val_d) + (2*val_a)
23 | return num / den
24 |
25 |
26 | def main():
27 | """ Main function """
28 | val_a = float(input())
29 | val_b = float(input())
30 | val_c = float(input())
31 | val_d = float(input())
32 |
33 | print(fun_x(fun_x(val_a)))
34 | print(gun_x(fun_x(val_a-val_b)))
35 | print(hun_x(fun_x(val_a+val_b), fun_x(val_a+val_c), gun_x(fun_x(pow(val_d, 2)))))
36 | ret_a = hun_x(fun_x(val_a+val_b), fun_x(val_a-val_c),
37 | gun_x(fun_x(pow(val_d, 2))))
38 | ret_b = gun_x(fun_x(val_a-val_b))
39 | ret_c = fun_x(fun_x(fun_x(fun_x(fun_x(val_c)))))
40 | print(iun_x(ret_a, ret_b, ret_c, pow(val_d, 8)))
41 |
42 |
43 | main()
44 |
--------------------------------------------------------------------------------
/Week4/Timing II.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def main():
5 | """Main function"""
6 | time = int(input())
7 | seconds = time % 60
8 | minutes = time//60
9 | hours = minutes//60
10 | minutes = minutes % 60
11 | days = hours//24
12 | hours = hours % 24
13 | if days <= 9999:
14 | print("%0.4d:%.2d:%.2d:%.2d" % (days, hours, minutes, seconds))
15 | elif days > 9999:
16 | print("ERR_:__:__:__")
17 |
18 |
19 | main()
20 |
--------------------------------------------------------------------------------
/Week5/BootSequence.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = int(input())
5 | for i in range(1, value+1):
6 | if i == value:
7 | print(i, end="")
8 | else:
9 | print(i, end="_")
10 | main()
11 |
--------------------------------------------------------------------------------
/Week5/BrickBridge.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value_a = int(input())
5 | value_b = int(input())
6 | value_gold = int(input())
7 | if value_gold % 5 > value_a or (value_a + (value_b * 5)) < value_gold:
8 | print(-1)
9 | else:
10 | if value_b * 5 >= value_gold:
11 | small = value_gold % 5
12 | else:
13 | small = value_gold-(value_b*5)
14 | print(small)
15 | main()
16 |
--------------------------------------------------------------------------------
/Week5/Circular 1.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | mypos_x = float(input())
5 | mypos_y = float(input())
6 | radius = float(input())
7 | pos_x = float(input())
8 | pos_y = float(input())
9 |
10 | distance = (((mypos_x-pos_x)**2) +((mypos_y-pos_y)**2))**0.5
11 | if distance <= radius:
12 | print("Yes")
13 | elif distance > radius:
14 | print("No")
15 | main()
16 |
--------------------------------------------------------------------------------
/Week5/Circular 2.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | my_pos_x = float(input())
5 | my_pos_y = float(input())
6 | radius = float(input())
7 | pos_x = float(input())
8 | pos_y = float(input())
9 | my_redius = float(input())
10 |
11 | distance = (((my_pos_x-pos_x)**2) +((my_pos_y-pos_y)**2))**0.5
12 | if distance >= radius + my_redius:
13 | print("No")
14 | elif distance < radius + my_redius:
15 | print("Yes")
16 | main()
17 |
--------------------------------------------------------------------------------
/Week5/Counter.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | for i in range(1, 101):
5 | print("%d" % i)
6 | main()
7 |
--------------------------------------------------------------------------------
/Week5/Day 1.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = int(input())
5 | if (value % 400 == 0) or (value % 100 != 0) and (value % 4 == 0):
6 | print("Yes")
7 | else:
8 | print("No")
9 | main()
10 |
--------------------------------------------------------------------------------
/Week5/Donut.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | price = int(input())
5 | amount = int(input())
6 | free = int(input())
7 | want = int(input())
8 |
9 | in_want = want // (amount + free)
10 | if want == 0:
11 | print("0 0")
12 | elif want > 0:
13 | donut = in_want*(amount + free)
14 | total_left = want - donut
15 | if total_left > amount:
16 | total_left = amount
17 | if total_left >= amount:
18 | donut = donut + (amount + free)
19 | else:
20 | donut = donut + total_left
21 |
22 | total_price = (price*in_want*amount) + (total_left*price);
23 | print("%d %d" % (total_price, donut))
24 | main()
25 |
--------------------------------------------------------------------------------
/Week5/GraderMachince.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | starter = int(input())
5 | breaker = int(input())
6 | total = 0
7 | print("pass :", end=" ")
8 | if starter < breaker:
9 | while starter <= breaker:
10 | if starter % 2 == 0:
11 | total += starter
12 | print("%d" % starter, end=" ")
13 | starter += 1
14 | else:
15 | while starter >= breaker:
16 | if starter % 2 == 0:
17 | total += starter
18 | print("%d" % starter, end=" ")
19 | starter -= 1
20 | print()
21 | print("Sum : %d" % total)
22 | main()
23 |
--------------------------------------------------------------------------------
/Week5/HideAndSeek.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | starter = int(input())
5 | breaker = int(input())
6 | stepper = int(input())
7 | for i in range(starter, breaker, stepper):
8 | print("%d" % i)
9 | main()
10 |
--------------------------------------------------------------------------------
/Week5/HowLong.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | increments = abs(int(input()))
5 | x_val = 0
6 | for _ in str(increments):
7 | x_val += 1
8 | print(x_val)
9 | main()
10 |
--------------------------------------------------------------------------------
/Week5/LargestNumber.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def compare_number(value_1, value_2):
3 | """Compare number"""
4 | if value_1 > value_2:
5 | return value_1
6 | return value_2
7 |
8 | def main():
9 | """Main function"""
10 | x_val = input()
11 | y_val = input()
12 | z_val = input()
13 |
14 | lastest = x_val + y_val + z_val
15 | lastest = compare_number((x_val + z_val + y_val), lastest)
16 | lastest = compare_number((y_val + x_val + z_val), lastest)
17 | lastest = compare_number((y_val + z_val + x_val), lastest)
18 | lastest = compare_number((z_val + y_val + x_val), lastest)
19 | lastest = compare_number((z_val + x_val + y_val), lastest)
20 | print(int(lastest))
21 | main()
22 |
--------------------------------------------------------------------------------
/Week5/PlanCDEFGHIJKLMNOPQRSTUVWXYZ.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | order = input()
5 |
6 | num1 = float(input())
7 | num2 = float(input())
8 | num3 = float(input())
9 |
10 | if num1 > num2:
11 | num1, num2 = num2, num1
12 | if num2 > num3:
13 | num2, num3 = num3, num2
14 | if num1 > num2:
15 | num1, num2 = num2, num1
16 |
17 | if order.lower() == "ascend":
18 | print("%.2f, %.2f, %.2f " %(num1, num2, num3))
19 | elif order.lower() == "descend":
20 | print("%.2f, %.2f, %.2f " %(num3, num2, num1))
21 |
22 | main()
23 |
--------------------------------------------------------------------------------
/Week5/Repeater.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = input()
5 | for _ in range(1, 101):
6 | print(value)
7 | main()
8 |
--------------------------------------------------------------------------------
/Week5/Runner.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | x_val = input()
5 | y_val = int(input())
6 |
7 | for _ in range(1, y_val + 1):
8 | print(x_val)
9 | main()
10 |
--------------------------------------------------------------------------------
/Week5/Stepper 1.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | breaker = int(input())
5 | for i in range(1, breaker + 1):
6 | print("%d" % i)
7 | main()
8 |
--------------------------------------------------------------------------------
/Week5/Stepper 2.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | starter = int(input())
5 | breaker = int(input())
6 | if breaker < starter:
7 | for i in range(starter, breaker-1, -1):
8 | print(i)
9 | elif breaker >= starter:
10 | for i in range(starter, breaker+1, 1):
11 | print(i)
12 | main()
13 |
--------------------------------------------------------------------------------
/Week5/SumOfNumber.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | x_val = []
5 | checked = int(input())
6 | while True:
7 | value = int(input())
8 | if value == -1:
9 | break
10 | x_val.append(value)
11 | if sum(x_val) == checked:
12 | break
13 | print(sum(x_val))
14 | main()
15 |
--------------------------------------------------------------------------------
/Week5/SurprisingVote.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | x_val = float(input())
5 | y_val = float(input())
6 |
7 | #Define defualt 0
8 | z_val = 0
9 | if y_val * 2 < x_val:
10 | z_val = x_val - y_val * 2
11 | if y_val - z_val > 2:
12 | print("Surprising")
13 | else:
14 | print("Not surprising")
15 | main()
16 |
--------------------------------------------------------------------------------
/Week5/Triangle 1.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | value = [float(input()), float(input()), float(input())]
5 | if value[0] > value[1]:
6 | value[1], value[0] = value[0], value[1]
7 | if value[1] > value[2]:
8 | value[1], value[2] = value[2], value[1]
9 | if value[0] > value[1]:
10 | value[1], value[0] = value[0], value[1]
11 |
12 | process = ((value[0]**2)+(value[1]**2))**0.5
13 | if value[2] <= process <= value[2]+0.01:
14 | print("Yes")
15 | else:
16 | print("No")
17 | main()
18 |
--------------------------------------------------------------------------------
/Week5/WeightStation.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """Main function"""
4 | average = float(input())
5 | val_a = float(input())
6 | val_b = float(input())
7 | val_c = float(input())
8 | val_d = (average * 4) - (val_a + val_b + val_c)
9 | less = average-(average/2)
10 | more = average + (average/2)
11 | if average * 4 > 15000:
12 | print("Overweight")
13 | elif less < val_a < more and less < val_b < more and less < val_c < more\
14 | and less < val_d < more:
15 | print("Pass %.2f"%val_d)
16 | else:
17 | print("Unbalance")
18 | main()
19 |
--------------------------------------------------------------------------------
/template.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 | def main():
3 | """ Main function """
4 | main()
5 |
--------------------------------------------------------------------------------
/test.py:
--------------------------------------------------------------------------------
1 | """IG: few.pz"""
2 |
3 |
4 | def main(n):
5 | """ Main function """
6 | List = range(-1, n*n+9, 2)
7 | i = 2
8 | while List[i:]:
9 | List = sorted(set(List) - set(List[List[i]::List[i]]))
10 | i += 1
11 | print(List[1:n+1])
12 |
13 |
14 | main(int(input()))
15 |
--------------------------------------------------------------------------------