Python Forum
Still confused about how passing arguments works
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Still confused about how passing arguments works
#1
I have a simple user input program:

#!/usr/bin/python
#QuickTest.py

def getLocation(x,y,z):
    x = input("Specify horizontal position: ")#latitude
    y = input("Specify vertical position: ")#longitude
    z = input("Specify altitude: ")#above sea level
    return x,y,z

def QuickTestMain():
##    x = 0
##    y = 0
##    z = 0
    getLocation(x,y,z)
    print("You are located at " + str(x) + "degrees latitude, " +
          str(y) + " degrees longitude, " + " and " + str(z) +
          " feet above sea level.")

QuickTestMain()
When lines 11 - 13 are not commented out, it just prints all 0's (I just wanted to initialize them, so that they exist in the program):
Error:
========== RESTART: I:/Python/Python36-32/SamsPrograms/QuickTest.py ========== Specify horizontal position: 3 Specify vertical position: 4 Specify altitude: 5 You are located at 0degrees latitude, 0 degrees longitude, and 0 feet above sea level. >>>
And then if I comment them out, I get:
Error:
========== RESTART: I:/Python/Python36-32/SamsPrograms/QuickTest.py ========== Traceback (most recent call last): File "I:/Python/Python36-32/SamsPrograms/QuickTest.py", line 19, in <module> QuickTestMain() File "I:/Python/Python36-32/SamsPrograms/QuickTest.py", line 14, in QuickTestMain getLocation(x,y,z) NameError: name 'x' is not defined >>>
How do I fix this?
Reply


Messages In This Thread
Still confused about how passing arguments works - by RedSkeleton007 - Apr-25-2018, 09:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problems passing arguments containing spaces to bash script and then on to python kaustin 6 424 Apr-03-2024, 08:26 PM
Last Post: deanhystad
  Passing writable arguments to functions. Assembler 11 1,020 Jan-15-2024, 11:32 PM
Last Post: sgrey
  String int confused janeik 7 1,087 Aug-02-2023, 01:26 AM
Last Post: deanhystad
  I am confused with the key and value thing james1019 3 980 Feb-22-2023, 10:43 PM
Last Post: deanhystad
  Passing string functions as arguments Clunk_Head 3 1,268 Jun-15-2022, 06:00 AM
Last Post: Gribouillis
  Pandas confused DPaul 6 2,586 Sep-19-2021, 06:45 AM
Last Post: DPaul
  is and '==' i'm confused hshivaraj 6 2,733 Sep-15-2021, 09:45 AM
Last Post: snippsat
  Confused with 'flags' tester_V 10 4,945 Apr-12-2021, 03:03 AM
Last Post: tester_V
  Simple Tic Tac Toe but I'm confused Izith 1 2,207 Sep-26-2020, 04:42 PM
Last Post: Larz60+
  I am really confused with this error. Runar 3 3,040 Sep-14-2020, 09:27 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020