Skip to content

Commit 954d029

Browse files
Add files via upload
1 parent 755f0dc commit 954d029

21 files changed

+614
-0
lines changed

5. While Loop/1. Lab/01. Read Text.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""
2+
Write a program that reads text from the console (string)
3+
and prints it until it receives the "Stop" command.
4+
"""
5+
6+
7+
text = input()
8+
9+
while text != 'Stop':
10+
print(text)
11+
text = input()

5. While Loop/1. Lab/02. Password.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
Write a program that initially reads a user profile name and password.
3+
It then reads a login password.
4+
5+
• when entering a wrong password: prompt the user to enter a new password.
6+
• when entering a correct password: we print "Welcome {username}!".
7+
"""
8+
9+
10+
user = input()
11+
password = input()
12+
data = input()
13+
14+
while data != password:
15+
data = input()
16+
17+
print(f"Welcome {user}!")
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
Write a program that reads an integer from the console
3+
and on each successive line integers until their sum is
4+
greater than or equal to the original number.
5+
6+
After reading is complete, print the sum of the entered numbers.
7+
"""
8+
9+
10+
number = int(input())
11+
12+
sum_num = 0
13+
14+
while sum_num < number:
15+
sum_text = int(input())
16+
sum_num += sum_text
17+
18+
print(sum_num)
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
Write a program that reads a number n entered by the user
3+
and prints all numbers ≤ n from the sequence: 1, 3, 7, 15, 31, ….
4+
5+
Each subsequent number is calculated by multiplying
6+
the previous one by 2 and adding 1.
7+
"""
8+
9+
10+
11+
number = int(input())
12+
13+
sum_num = 1
14+
15+
while sum_num <= number:
16+
print(sum_num)
17+
sum_num = sum_num * 2 + 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
Write a program that calculates how much total money is in
3+
the account after you make a certain number of deposits.
4+
5+
On each line you will receive the amount you need to deposit
6+
into the account until you receive a "NoMoreMoney" command.
7+
8+
For each amount received, the console should display
9+
"Increase: " + the amount and add it to the account.
10+
11+
If you get a number less than 0 the console should display
12+
13+
"Invalid operation!" and the program to end.
14+
15+
When the program ends, it should print
16+
17+
"Total: " + the total amount in the account
18+
19+
formatted to the second decimal place.
20+
"""
21+
22+
23+
money = input()
24+
current_sum = 0
25+
26+
while money != "NoMoreMoney":
27+
if float(money) < 0:
28+
print("Invalid operation!")
29+
break
30+
31+
print(f"Increase: {float(money):.2f}")
32+
current_sum += float(money)
33+
money = input()
34+
35+
print(f"Total: {current_sum:.2f}")
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
Write a program that, until the
3+
"Stop" command is received, reads integers
4+
entered by the user, finds the largest among them,
5+
and prints it. Enter one number per line.
6+
"""
7+
8+
9+
import sys
10+
11+
number = input()
12+
max_num = - sys.maxsize
13+
14+
while number != "Stop":
15+
num = int(number)
16+
17+
if num > max_num:
18+
max_num = num
19+
20+
number = input()
21+
22+
print(max_num)
23+
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
Write a program that, until receiving the "Stop"
3+
command, reads integers entered by the user,
4+
finds the smallest among them, and prints it.
5+
6+
Enter one number per line.
7+
"""
8+
9+
10+
import sys
11+
12+
number = input()
13+
min_num = sys.maxsize
14+
15+
while number != "Stop":
16+
num = int(number)
17+
18+
if num < min_num:
19+
min_num = num
20+
21+
number = input()
22+
23+
print(min_num)
24+
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
Write a program that calculates the grade point average of a student over his entire course.
3+
4+
On the first line, you will get the student's name, and on each subsequent line,
5+
their annual grades. The student advances to the next grade if his annual grade is
6+
greater than or equal to 4.00. If the student is interrupted more than once,
7+
the student is expelled and the program ends, printing the name of the student and
8+
the class in which he was expelled.
9+
10+
On successful completion of 12th grade to print:
11+
12+
"{student name} graduated. Average grade: {the average grade of the entire study}"
13+
14+
In case the student is excluded from school, print:
15+
"{student name} has been excluded at {grade in which he was excluded} grade"
16+
17+
The value must be formatted to the second decimal place.
18+
"""
19+
20+
21+
22+
student_name = input()
23+
24+
current_class = 1
25+
total_grade = 0
26+
fail = 0
27+
28+
is_excluded = False
29+
30+
while current_class <= 12:
31+
current_grade = float(input())
32+
33+
if current_grade < 4:
34+
fail += 1
35+
if fail > 1:
36+
is_excluded = True
37+
break
38+
39+
else:
40+
current_class += 1
41+
total_grade += current_grade
42+
43+
if is_excluded:
44+
print(f"{student_name} has been excluded at {current_class} grade")
45+
else:
46+
average_grade = total_grade / 12
47+
print(f"{student_name} graduated. Average grade: {average_grade:.2f}")
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
Annie goes to her hometown after a very long period outside the country.
3+
On her way home, she sees her grandmother's old library and remembers her favorite book.
4+
Help Annie by writing a program in which she enters the book (text) she is looking for.
5+
Until Annie finds her favorite book or checks out all the books in the library,
6+
the program must read each time on a new line the name of each subsequent
7+
book (text) she checks out. The books in the library are out of stock once you get
8+
the "No More Books" text.
9+
10+
• If it does not find the requested book to be printed on two lines:
11+
"The book you are looking for is not here!"
12+
"You checked {number} books."
13+
• If he finds his book, one line is printed:
14+
"You checked {number} books and found it."
15+
"""
16+
17+
18+
book_title = input()
19+
book_from_shelf = input()
20+
21+
checked_books = 0
22+
23+
while book_title != book_from_shelf:
24+
if book_from_shelf == "No More Books":
25+
print("The book you search is not here!")
26+
print(f"You checked {checked_books} books.")
27+
break
28+
29+
checked_books += 1
30+
book_from_shelf = input()
31+
32+
else:
33+
print(f"You checked {checked_books} books and found it.")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
Write a program in which Marin solves exam problems until she receives an
3+
"Enough" message from her lecturer. For each solved task he gets a grade.
4+
5+
The program should stop reading data on the command "Enough" or if Marin
6+
receives the specified number of unsatisfactory marks.
7+
8+
Any score less than or equal to 4 is unsatisfactory.
9+
"""
10+
11+
12+
13+
bad_grades = int(input())
14+
problem_title = input()
15+
grade_total = 0
16+
solved_problems = 0
17+
last_problem = ""
18+
bad_grade_count = 0
19+
20+
while problem_title != "Enough":
21+
grade = int(input())
22+
23+
grade_total += grade
24+
solved_problems += 1
25+
last_problem = problem_title
26+
27+
if grade <= 4:
28+
bad_grade_count += 1
29+
if bad_grade_count >= bad_grades:
30+
print(f"You need a break, {bad_grade_count} poor grades.")
31+
break
32+
33+
problem_title = input()
34+
35+
else:
36+
average_score = grade_total / solved_problems
37+
38+
print(f"Average score: {average_score:.2f}")
39+
print(f"Number of problems: {solved_problems}")
40+
print(f"Last problem: {last_problem}")
41+
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Jessie has decided to raise money for a field trip and she wants you to help
3+
her find out if she will be able to raise the necessary amount.
4+
5+
She saves or spends some of her money every day. If she wants to spend more
6+
than her available money, she will spend as much as she has and she will have BGN 0 left.
7+
"""
8+
9+
10+
11+
needed_money = float(input())
12+
available_money = float(input())
13+
days = 0
14+
days_spent = 0
15+
16+
while available_money < needed_money:
17+
action = input()
18+
action_money = float(input())
19+
days += 1
20+
if action == "save":
21+
available_money += action_money
22+
days_spent = 0
23+
else:
24+
available_money -= action_money
25+
if available_money < 0:
26+
available_money = 0
27+
days_spent += 1
28+
if days_spent == 5:
29+
print("You can't save the money.")
30+
print(days)
31+
break
32+
else:
33+
print(f"You saved the money for {days} days.")
34+
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
Gabby wants to start a healthy lifestyle and has set a goal of walking 10,000 steps every day.
3+
Some days, however, she is very tired from work and will want to go home before she achieves her goal.
4+
5+
Write a program that reads from the console how many steps she takes each time she goes out during the day,
6+
and when she reaches her goal it says
7+
8+
"Goal reached! Good job!" and how many more steps did "{difference between steps} steps over the goal!"
9+
10+
If she wants to go home before then, she will enter the command "Going home" and enter the steps she took
11+
on her way home. After which, if she failed to reach her goal, the console should read:
12+
13+
"{difference between steps} more steps to reach goal."
14+
"""
15+
16+
17+
18+
input_line = input()
19+
steps_count = 0
20+
21+
while input_line != "Going home":
22+
steps = int(input_line)
23+
steps_count += steps
24+
if steps_count >= 10000:
25+
break
26+
27+
input_line = input()
28+
29+
if input_line == "Going home":
30+
steps_home = int(input())
31+
steps_count += steps_home
32+
33+
diff = abs(10000 - steps_count)
34+
35+
if steps_count >= 10000:
36+
print("Goal reached! Good job!")
37+
print(f"{diff} steps over the goal!")
38+
else:
39+
print(f"{diff} more steps to reach goal.")
40+
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Vending machine manufacturers wanted to make their machines return as little change as possible.
3+
Write a program that takes an amount - the change to be returned and calculates the least number
4+
of coins that can be returned.
5+
"""
6+
7+
8+
9+
change = float(input())
10+
coins_change = round(change * 100)
11+
12+
count_coins = 0
13+
14+
while coins_change > 0:
15+
if coins_change >= 200:
16+
coins_change -= 200
17+
elif coins_change >= 100:
18+
coins_change -= 100
19+
elif coins_change >= 50:
20+
coins_change -= 50
21+
elif coins_change >= 20:
22+
coins_change -= 20
23+
elif coins_change >= 10:
24+
coins_change -= 10
25+
elif coins_change >= 5:
26+
coins_change -= 5
27+
elif coins_change >= 2:
28+
coins_change -= 2
29+
elif coins_change >= 1:
30+
coins_change -= 1
31+
count_coins += 1
32+
33+
print(count_coins)
34+

0 commit comments

Comments
 (0)