-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday_10.py
More file actions
192 lines (133 loc) · 4.41 KB
/
day_10.py
File metadata and controls
192 lines (133 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# Functions with Outputs
# mój przykład
# def format_name(f_name, l_name):
# # f_name = input("What is your first name?: ").lower()
# # l_name = input("What is your last name?: ").lower()
# return (f_name + " " + l_name).title()
# print(format_name("magdalena", "rajewska"))
# z kursu
# #Functions with Outputs
# def format_name(f_name, l_name):
# if f_name == "" or l_name == "":
# return "You didn't provide valid inputs."
# formated_f_name = f_name.title()
# formated_l_name = l_name.title()
# f"Result: {formated_f_name} {formated_l_name}"
# #Storing output in a variable
# formatted_name = format_name(input("Your first name: "), input("Your last name: "))
# print(formatted_name)
# #or printing output directly
# print(format_name(input("What is your first name? "), input("What is your last name? ")))
# #Already used functions with outputs.
# length = len(formatted_name)
# #Return as an early exit
# def format_name(f_name, l_name):
# """Take a first and last name and format it
# to return the title case version of the name."""
# if f_name == "" or l_name == "":
# return "You didn't provide valid inputs."
# formated_f_name = f_name.title()
# formated_l_name = l_name.title()
# return f"Result: {formated_f_name} {formated_l_name}"
# zadanie 1
# def is_leap(year):
# if year % 4 == 0:
# if year % 100 == 0:
# if year % 400 == 0:
# return True
# else:
# return False
# else:
# return True
# else:
# return False
# def days_in_month(year, month):
# """ funkcja daje ilość dni w danym miesiącu"""
# month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
# if month > 12 or month < 1:
# return "Invalid month entered."
# if month == 2 and is_leap(year):
# return 29
# return month_days[month-1]
# # (moje)
# # ind = check_month - 1
# # if is_leap(year) == True:
# # if ind == 1:
# # return "That february has 29 days"
# # else:
# # return month_days[month - 1]
# #🚨 Do NOT change any of the code below
# year = int(input("Enter a year: "))
# month = int(input("Enter a month: "))
# days = days_in_month(year, month)
# print(days)
# Calculator
# # Add
# def add(n1, n2):
# return n1 + n2
# # Substract
# def substract(n1, n2):
# return n1 - n2
# def multiply(n1, n2):
# return n1 * n2
# def divide(n1, n2):
# return n1 / n2
# operations = {
# "+": add,
# "-": substract,
# "*": multiply,
# "/": divide}
# def calculator(num1, num2):
# calculation_function = operations[operation_symbol]
# answer = calculation_function(num1, num2)
# print(f"{num1} {operation_symbol} {num2} = {answer}")
# return answer
# go_on = False
# while not go_on:
# num1 = int(input("What's the first number?: "))
# for symbol in operations:
# print(symbol)
# operation_symbol = input("Pick an operation from the line above: ")
# num2 = int(input("What's the second number?: "))
# result = calculator(num1, num2)
# decision = input(f"Type 'y' to continue calculating with {result}, or type 'n' to exit: ").lower
# if decision == "y":
# next = int(input("What's the next number?: "))
# calculator(result, next)
# go_on = False
# else:
# go_on = True
# Add
def add(n1, n2):
return n1 + n2
# Substract
def substract(n1, n2):
return n1 - n2
def multiply(n1, n2):
return n1 * n2
def divide(n1, n2):
return n1 / n2
operations = {
"+": add,
"-": substract,
"*": multiply,
"/": divide}
for symbol in operations:
print(symbol)
def calculator(num1):
symbol = input("Pick an operation: ")
next_num = int(input("What's the next number?: ")
calculation_function = operations[symbol]
answer = calculation_function(num1, next_num)
print(f"{num1} {symbol} {next_num} = {answer}")
return answer
num1 = int(input("What's the first number?: "))
go_on = False
while not go_on:
result = calculator(num1)
decision = input(f"Type 'y' to continue calculating with {result}, or type 'n' to exit: ").lower()
if decision == "y":
calculator(result)
go_on = False
else:
go_on = True