Skip to content

Commit 755f0dc

Browse files
Add files via upload
1 parent ac8acfb commit 755f0dc

30 files changed

+927
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""
2+
Write a program that prints the numbers 1 to 100, each on a new line.
3+
"""
4+
5+
for i in range(1, 100 + 1):
6+
print(i)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""
2+
Write a program that reads a number n
3+
entered by the user and prints the numbers 1 through n through 3.
4+
"""
5+
6+
n = int(input())
7+
8+
for i in range(1, n + 1, 3):
9+
print(i)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""
2+
Write a program that reads a number n entered by the user
3+
and prints the even powers of 2 ≤ 2n: 20, 22, 24, 26, …, 2n.
4+
"""
5+
6+
n = int(input())
7+
8+
for i in range(0, n + 1, 2): # iterate with a step of 2 for even numbers
9+
print(2**i) # 2^0 = 1

4. For Loop/1. Lab/04. Numbers N 1.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""
2+
Write a program that reads a positive integer n entered by the user
3+
and prints the numbers n through 1 in reverse order.
4+
5+
The number n entered will always be greater than 1.
6+
"""
7+
8+
n = int(input())
9+
10+
for i in range(n, 0, -1):
11+
print(i)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""
2+
Write a program that reads text (string)
3+
entered by the user and prints each character
4+
of the text on a separate line.
5+
"""
6+
7+
text = input()
8+
9+
for i in text:
10+
print(i)

4. For Loop/1. Lab/06. Vowels Sum.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
To write a program that reads text (string) entered by the user
3+
and calculates and prints the sum of the vowel values according to the table below:
4+
5+
letter a e i o u
6+
value 1 2 3 4 5
7+
"""
8+
9+
text = input()
10+
result = 0
11+
12+
for i in range(0, len(text)):
13+
if text[i] == "a":
14+
result += 1
15+
if text[i] == "e":
16+
result += 2
17+
if text[i] == "i":
18+
result += 3
19+
if text[i] == "o":
20+
result += 4
21+
if text[i] == "u":
22+
result += 5
23+
24+
print(result)

4. For Loop/1. Lab/07. Sum Numbers.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
Write a program that reads n-th number of integers
3+
entered by the user and sums them.
4+
5+
• The number of numbers n is entered from the first line of the input.
6+
• One whole number is entered from the next n lines.
7+
8+
The program must read the numbers, add them, and print the sum.
9+
"""
10+
11+
12+
count_of_numbers = int(input())
13+
sum_of_numbers = 0
14+
15+
for i in range(count_of_numbers):
16+
current_number = int(input())
17+
sum_of_numbers += current_number
18+
19+
print(sum_of_numbers)
20+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Write a program that reads n number of integers.
3+
4+
Print the largest and smallest number among those entered.
5+
"""
6+
7+
8+
import sys
9+
10+
iterations = int(input())
11+
12+
max_num = -sys.maxsize
13+
min_num = sys.maxsize
14+
number = 0
15+
16+
for nums in range(iterations):
17+
number = int(input())
18+
19+
if number > max_num:
20+
max_num = number
21+
22+
if number < min_num:
23+
min_num = number
24+
25+
print(f"Max number: {max_num}")
26+
print(f"Min number: {min_num}")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
Write a program that reads 2 * n-th number of integers
3+
supplied by the user and checks whether the sum of the first n numbers
4+
5+
(left sum) is equal to the sum of the second n numbers (right sum).
6+
7+
If there is a tie, print " Yes, sum = " + the sum;
8+
9+
otherwise it prints " No, diff = " + the difference.
10+
11+
The difference is calculated as a positive number (in absolute value).
12+
"""
13+
14+
15+
iterations = int(input())
16+
17+
left_sum = 0
18+
right_sum = 0
19+
20+
for numbers in range(iterations * 2):
21+
current_num = int(input())
22+
if numbers < iterations:
23+
left_sum += current_num
24+
else:
25+
right_sum += current_num
26+
27+
if left_sum == right_sum:
28+
print(f"Yes, sum = {left_sum}")
29+
else:
30+
diff = abs(left_sum - right_sum)
31+
print(f"No, diff = {diff}")
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Write a program that reads n-th number of integers
3+
supplied by the user and checks whether the sum of the numbers
4+
in even positions is equal to the sum of the numbers in odd positions.
5+
6+
• If the sums are equal, print two lines: "Yes" and on a new line "Sum = " + the sum;
7+
• If the amounts are not equal, print two lines: "No" and on a new line "Diff = " + the difference.
8+
9+
The difference is calculated in absolute value.
10+
"""
11+
12+
13+
14+
n = int(input())
15+
16+
odd_sum = 0
17+
even_sum = 0
18+
19+
for position in range(1, n + 1):
20+
current_num = int(input())
21+
if position % 2 == 0:
22+
even_sum += current_num
23+
else:
24+
odd_sum += current_num
25+
26+
if even_sum == odd_sum:
27+
print(f"Yes")
28+
print(f"Sum = {even_sum}")
29+
else:
30+
diff = abs(even_sum - odd_sum)
31+
print(f"No")
32+
print(f"Diff = {diff}")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""
2+
Write a program that prints the numbers in the range 1 to 1000 that end in 7.
3+
"""
4+
5+
for i in range(1, 1001):
6+
if i % 10 == 7:
7+
print(i)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Write a program that reads n-th number of integers entered by the user and checks
3+
if there is a number among them that is equal to the sum of all the others.
4+
5+
• If there is such an element, print "Yes" and on a new line "Sum = " + its value
6+
• If there is no such element, print "No" and on a new line "Diff = " + the difference
7+
between the largest element and the sum of the others (by absolute value)
8+
"""
9+
10+
11+
import sys
12+
13+
iterations = int(input())
14+
15+
max_num = -sys.maxsize
16+
sum_numbers = 0
17+
18+
for number in range(iterations):
19+
num = int(input())
20+
sum_numbers += num
21+
if num > max_num:
22+
max_num = num
23+
24+
sum_numbers -= max_num
25+
diff = abs(max_num - sum_numbers)
26+
27+
if sum_numbers == max_num:
28+
print(f"Yes")
29+
print(f"Sum = {sum_numbers}")
30+
else:
31+
print(f"No")
32+
print(f"Diff = {diff}")
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""
2+
Given n integers in the interval [1…1000]. Of these, some percentage p1 are below 200,
3+
another percentage p2 are from 200 to 399, another percentage p3 are from 400 to 599,
4+
another percentage p4 are from 600 to 799 and the remaining p5 percentage are from 800 and above.
5+
6+
Write a program that calculates and prints the percentages p1, p2, p3, p4 and p5.
7+
Example: we have n = 20 numbers: 53, 7, 56, 180, 450, 920, 12, 7, 150, 250, 680, 2,
8+
600, 200, 800, 799, 199, 46, 128, 65.
9+
10+
We get the following distribution and visualization:
11+
12+
Range Numbers in range Number of numbers Percent
13+
< 200 53, 7, 56, 180, 12, 7, 150, 2, 199, 46, 128, 65 12 p1 = 12 / 20 * 100 = 60.00%
14+
200 … 399 250, 200 2 p2 = 2 / 20 * 100 = 10.00%
15+
400 … 599 450 1 p3 = 1 / 20 * 100 = 5.00%
16+
600 … 799 680, 600, 799 3 p4 = 3 / 20 * 100 = 15.00%
17+
≥ 800 920, 800 2 p5 = 2 / 20 * 100 = 10.00%
18+
"""
19+
20+
21+
n = int(input())
22+
23+
p1 = 0
24+
p2 = 0
25+
p3 = 0
26+
p4 = 0
27+
p5 = 0
28+
29+
for numbers in range(n):
30+
num = int(input())
31+
32+
if num < 200:
33+
p1 += 1
34+
elif 200 <= num <= 399:
35+
p2 += 1
36+
elif 400 <= num <= 599:
37+
p3 += 1
38+
elif 600 <= num <= 799:
39+
p4 += 1
40+
elif num >= 800:
41+
p5 += 1
42+
43+
p1_percent = (p1 / n) * 100
44+
p2_percent = (p2 / n) * 100
45+
p3_percent = (p3 / n) * 100
46+
p4_percent = (p4 / n) * 100
47+
p5_percent = (p5 / n) * 100
48+
49+
print(f"{p1_percent:.2f}%")
50+
print(f"{p2_percent:.2f}%")
51+
print(f"{p3_percent:.2f}%")
52+
print(f"{p4_percent:.2f}%")
53+
print(f"{p5_percent:.2f}%")
54+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
Lily is now N years old. For every birthday she gets a present.
3+
• For odd birthdays (1, 3, 5...n) he gets toys.
4+
• For even birthdays (2, 4, 6...n) he receives money.
5+
6+
For the second birthday, he receives BGN 10.00, and the amount increases
7+
by BGN 10.00 for each subsequent even birthday (2 -> 10, 4 -> 20, 6 -> 30...etc.).
8+
9+
Over the years, Lily has secretly saved the money. Lily's brother, in the years
10+
that she receives money, takes BGN 1.00 from them. Lily sold the toys received
11+
over the years, each for P leva and added the amount to the money saved.
12+
13+
With the money, she wanted to buy a washing machine for BGN X. Write a program
14+
to calculate how much money she has collected and whether she has enough to buy a washing machine.
15+
"""
16+
17+
18+
lily_age = int(input())
19+
washing_machine = float(input())
20+
one_toy_price = int(input())
21+
22+
birthday = 0
23+
brother_money = 0
24+
counter = 0
25+
toys = 0
26+
27+
for age in range(lily_age):
28+
counter += 1
29+
if counter % 2 == 0:
30+
birthday += (counter / 2) * 10
31+
brother_money += 1
32+
else:
33+
toys += 1
34+
35+
money_for_toys = one_toy_price * toys
36+
total_money = birthday - brother_money
37+
diff = abs((money_for_toys + total_money) - washing_machine)
38+
39+
if money_for_toys + total_money >= washing_machine:
40+
print(f"Yes! {diff:.2f}")
41+
else:
42+
print(f"No! {diff:.2f}")
43+

4. For Loop/2. Exercise/05. Salary.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
A company boss notices that more and more employees are spending time on distracting websites.
3+
To prevent this, it implements surprise checks on its employees' open browser tabs.
4+
5+
According to the open site in taba, the following fines are imposed:
6+
• "Facebook" -> BGN 150
7+
• "Instagram" -> BGN 100
8+
• "Reddit" -> BGN 50
9+
10+
Two lines are read from the console:
11+
• Number of open tabs in the browser n - an integer in the interval [1...10]
12+
• Salary - number in the interval [500...1500]
13+
Then n - number of times website name - text is read
14+
"""
15+
16+
17+
count_open_tabs = int(input())
18+
salary = int(input())
19+
20+
for i in range(count_open_tabs):
21+
website = input()
22+
if website == "Facebook":
23+
salary -= 150
24+
elif website == "Instagram":
25+
salary -= 100
26+
elif website == "Reddit":
27+
salary -= 50
28+
if salary <= 0:
29+
print("You have lost your salary.")
30+
break
31+
32+
if salary > 0:
33+
print(f"{int(salary)}")
34+

4. For Loop/2. Exercise/06. Oscars.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
You are invited by the academy to write software to calculate the points for an actor/actress.
3+
The academy will give you initial points for the actor.
4+
Each rater will then give their rating.
5+
6+
he points the actor receives are formed by: the length of the evaluator's
7+
name multiplied by the points he gives divided by two.
8+
9+
If the score at any point exceeds 1250.5 the program should abort and
10+
print that the given actor has received a nomination.
11+
12+
"""
13+
14+
15+
16+
actors_name = input()
17+
academy_points = float(input())
18+
n_graders = int(input())
19+
20+
final_points = academy_points
21+
22+
for i in range(n_graders):
23+
grader_name = input()
24+
grader_points = float(input())
25+
final_points += (len(grader_name) * grader_points) / 2
26+
if final_points > 1250.5:
27+
print(f"Congratulations, {actors_name} got a nominee for leading role with {final_points:.1f}!")
28+
break
29+
30+
diff = 1250.5 - final_points
31+
32+
if final_points <= 1250.5:
33+
print(f"Sorry, {actors_name} you need {diff:.1f} more!")
34+

0 commit comments

Comments
 (0)