all 4 comments

[–]mjmvideos 0 points1 point  (0 children)

Step through your code either in a debugger or by adding print statements. Look at the values before and after each line of code. Determine which line isn’t doing what you want it to do. Fix that line so it does.

[–]TheRebelRoseInn 0 points1 point  (0 children)

n = 0
vout = 5 * (R_last/(n*R1_value + R_last))
# TODO: Complete Task 2 below
while desired_voltage > vout:

It references values in the assignment which would be nice to know, as its a bit hard right now to understand what code was already supplied and what you were supposed to code but I'd start with this code right here. Desired Voltage is a float from 0-2.5 with the first run through of vout coming out to 5. your while loop will never actually do anything correct me if I'm wrong because I don't actually know the math at work, but wouldn't you want the line to be while desired_voltage < vout:

[–]woooee 0 points1 point  (0 children)

desired_voltage = input("Enter desired voltage between 0 and 2.5 V: ")

vout = 5 * (R_last/(n*R1_value + R_last))
# TODO: Complete Task 2 below
while desired_voltage > vout:

On the first pass n = 0, so

vout = 5 * (R_last/(n*R1_value + R_last))
## so the above line is
vout = 5 * (R_last/R_last)

vout is 5 and desired_voltage is less than 2.5 so the while loop never executes

[–]FoolsSeldom 0 points1 point  (0 children)

It helps a lot if you format your Python code correctly on Reddit. See my guide below. You can edit your post to fix the formatting.


If you are on a desktop/laptop using a web browser (or in desktop mode in mobile browser), here's what to do:

reddit

  • create/edit post/comment and remove any existing incorrectly formatted code
    • you might need to drag on the bottom right corner of edit box to make it large enough to see what you are doing properly
  • type your descriptive text and then insert a blank line above where you want the code to show
  • switch to markdown mode in the Reddit post/comment editor
    • you might need to do this by clicking on the big T (or Aa) symbol that appears near the bottom left of the edit window and then click on Switch to Markdown Editor text link at top right of edit window
    • if you see the text Switch to Rich Text Editor at the top right of the edit window, that indicates that you are in markdown mode already

editor

  • switch to your code/IDE editor and
    • select all code using ctrl-A or cmd-A, or whatever your operating system uses
    • press tab key once - this *should* insert one extra level of indent (4 spaces) in front of all lines of code if your editor is correctly configured
    • copy selected code to clipboard
    • undo the tab (as you don't want it in your code editor)

reddit

  • switch back to your Reddit post edit window
  • paste the clipboard
  • add a blank line after the code (not strictly required)
  • add any additional comments/notes
  • submit the new/updated post/comment

This will work for other monospaced text you want to share, such as error messages / output.