Itachi Sama Itachi Sama - 4 months ago 6
Python Question

python basic show and return values

I'm using python to input data to my script

then trying to return it back
on demand to show the results

I tried to write it as simple as possible since it's only practicing and trying to get the hang of python

here's how my script looks like

#!/usr/python

## imports #####
##################
import os
import sys

## functions
##################

# GET INSERT DATA
def getdata():
clientname = raw_input(" *** Enter Client Name > ")
phone = raw_input(" *** Enter Client Phone > ")
location = raw_input(" *** Enter Client Location > ")
email = raw_input(" *** Enter Client email > ")
website = raw_input(" *** Enter Client Website > ")
return clientname, phone, location, email, website

# VIEW DATA
def showdata():

print "==================="
print ""
print clientname
print ""
print phone
print ""
print location
print ""
print email
print ""
print website
print ""
print "==================="

# CLEAR
def clear():
os.system("clear") #linux
os.system("cls") #windows

# SHOW INSTRUCTIONS
def welcome():
clear()
while True:
choice = raw_input(" Select Option > ")
# INSERT DATA
if choice == "1":
getdata()


# VIEW DATA
elif choice == "2":
showdata()

else:
print "Invalid Selection.. "
print "Terminating... "
#exit()
welcome()


what am i doing wrong ? what am i missing?

Answer

Your getdata() function returns five values. That means when you call it, you can get five values out.

clientname, phone, location, email, website = getdata()

Then you can pass those into showdata() as arguments, if you change the function definition to say:

def showdata(clientname, phone, location, email, website):

and call it with:

showdata(clientname, phone, location, email, website)

But of course, that will fail if the user tries to show the data before they have input the data.