I have an assignment coming up where I have to create a currency converter using python, but I’m really confused on where or how to begin. Does anyone have any tips on how I could start? Like how would I make a simple window that displays two different currency slots? Any help is much appreciated, thank you!
A good place to start is by writing out in pseudocode the steps that need to happen in order to solve the problem. At this stage you don’t need to know all of the syntax or algorithms to complete the task. You’re just outlining the logic or a roadmap that you are going to follow. Pseudocode will also help to clarify the particular area or areas of your question on how to create a currency converter.
*** Please take note, that since this is a homework question (and forum rules), we can supply guidance but not code solutions. I do not think you are asking for a solution but just want to explain why I have given more of a guidance answer.
By the way, I did a very quick search on YouTube, and there are several tutorials there that can get you started as well.
Thank you so much for replying. Yup, so at the beginning when I was doing research, I could only find tutorials and coding using Tkinter, but because I’ve never learnt how to use imported libraries (and I’m not even sure I’m allowed to use it for this assignment) I resorted to asking everyone here. What exactly is pseudocode?
^^ To basically look like that
My assignment is meant to be creative and it’s not meant to be based on real currencies. So, not a lot of maths would be involved. But I’m just really stuck on creating the actual window itself. I tried using def setup and def draw functions but I’m still stuck
I’m not sure what you mean by “window” – Processing spawns a display window every time you run the code?
The way I see it, you need four Processing functions to make this work: setup() and draw() to structure the sketch; and mouseClicked() and keyPressed() to capture mouse and keyboard input. What follows is a basic scaffold.
The setup() and draw() look like this (I’m just drawing the input field here):
amount = '' # text you see in the input field
fieldstroke = '#000000' # stroke color for the input field
result = 0
def setup():
size(500, 500)
textSize(25)
strokeWeight(3)
def draw():
background('#999999')
# draw text input field
fill('#FFFFFF')
stroke(fieldstroke)
rect(40, 60, 150, 50)
fill(0)
text(amount, 55, 95)
'''
# draw result button
fill('#0000FF')
...
The variables (amount, fieldstroke, result) control the ‘app’ state. The mouseClicked() function interacts with those variables to affect the state:
def mouseClicked():
global fieldstroke, result
# select input field when it's clicked
if (mouseX > 40 and mouseX < 40+150 and
mouseY > 60 and mouseY < 60+50):
fieldstroke = '#FF0000'
'''
# result (blue button) code
if (mouseX > 200 and mouseX < 200+50 and
mouseY > 60 and mouseY < 60+50):
...
Now, for the keyPressed() section. If the field stroke is red, you can type text into it (by affecting the amount variable):
def keyPressed():
global amount
# if the input field has a red stroke, change the amount
if fieldstroke == '#FF0000':
amount += key
That should be enough to get you heading in the right direction.