Well, today I dove deeper into Python 3 and tried some new functions. It’s pretty hard, so if you are not that experienced, you may want to learn the basics of this language. You could read one of my past blogs about the very first Python basics. Let’s get started now.
DMOJ Problem
In DMOJ, there was quite a question. So there someone who has an amount of sugar. Let’s call the amount a. You need b amount of sugar. You have c amount of toothpaste but need d amount of it. Determine is you need to go to the groceries for sugar or go to the pharmacy for toothpaste, or go to the department store for both.
Solution
First, a, b, c, and d have to be ‘ints’ (integers). create an if statement. If means, well, you know, if.
if a < b and c < d:
You understand this, do you? I suppose yes.
That means you’ll go to… yes! The department store!
print(“Go to the department store”)
Do you know ‘elif‘? It’s like if.
Now, if we have not enough sugar…
elif a < b:
print(“Go to the grocery store”)
If not enough toothpaste,
elif c < d:
print(“Go to the pharmacy”)
Oh! if you run this and insert 1 2 3 4, you will get:
Go to the department store
Go to the grocery store
Go to the pharmacy
Just add…
a, b, c, d = map(int, input().split())
At the front. This helps, just try!