question on function -passing arguement

A forum for general discussion of the Python programming language.

question on function -passing arguement

Postby zahrein » Sat May 11, 2013 11:19 pm

This is my code. I dont understand why my check_kereta(no_pilihan) is having an error. It mention that i cant pass the argument.do help thanks.

Code: Select all
#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      zahrein
#
# Created:     09/05/2013
# Copyright:   (c) zahrein 2013
# Licence:     <your licence>
#-------------------------------------------------------------------------------

import random
import time

def the_introduction():
    print 'selamat datang ke  dunia  EV'
    print 'Kena mahir Python dan Test  \n so skg kena buat kerja  sungguh-sungguh\n Welcome Zahrein'


def pilih_kereta():
    print 'kereta maanakah yang menjadi idaman mu no 1 atau no2 '
    pilihan_kereta= input()
    if pilihan_kereta >=3:
        print 'wrong'

    return pilihan_kereta


def check_kereta():
    print 'halo man'
    time.sleep(5)
    print 'whatsapp'
    time.sleep(5)

    harapan= random.randint(1,2)
    print harapan



#  my functions
the_introduction()
no_pilihan = pilih_kereta()
#print 'pilih no %s ' %no_pilihan
check_kereta(no_pilihan)





zahrein
 
Posts: 15
Joined: Wed Apr 03, 2013 1:45 am

Re: question on function -passing arguement

Postby hrs » Sat May 11, 2013 11:36 pm

Next time please include the exact error, all of it. It's called a "trace back".

Your function "check_kereta()" doesn't take any arguments, yet you provide one. You provide "no_pilihan". Even if you would change the function to
Code: Select all
def check_kereta(my_pilhan_argument_or_whatever):
    print 'halo man'
    time.sleep(5)
    print 'whatsapp'
    time.sleep(5)

    harapan= random.randint(1,2)
    print harapan

There seems to be nothing in the function requiring an argument. What are you trying to do?
hrs
 
Posts: 86
Joined: Thu Feb 07, 2013 9:26 pm

Re: question on function -passing arguement

Postby zahrein » Sun May 12, 2013 11:23 pm

HI Hrs,
THanks for the feedback. And i will state clearly the error next time. After putting the arguments at the function like you did, it is working fine.
zahrein
 
Posts: 15
Joined: Wed Apr 03, 2013 1:45 am

Re: question on function -passing arguement

Postby hrs » Mon May 13, 2013 7:30 pm

While it does work, you're not doing anything with the argument that you pass. So unless you want to use the argument later on, it would be a better solution to restore the function definition to what it was and not pass any argument at all.
hrs
 
Posts: 86
Joined: Thu Feb 07, 2013 9:26 pm


Return to General Discussions

Who is online

Users browsing this forum: Yoriz and 2 guests