beth1234534
Badges: 9
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#1
Report Thread starter 2 years ago
#1
Hi can anyone help me please? Does anyone know how to call a def function in python?! So stuck and really don't want to ask my teacher because he already thinks I'm stupid 😖
0
reply
Strange5050
Badges: 17
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#2
Report 2 years ago
#2
Def is used to marks the start of the header of a function. You can almost see it as 'define', and is used when you first 'define' a function in your program. For example.

Code:
def sayHello():
    print("Hello World")
sayHello is the function, if we were to call this function later in the program, we can simply say:
Code:
sayHello() // This will output "Hello World".
Some functions will feature what we call 'parameters', and these are basically inputs we can use in our functions:
Code:
def sayName(name):
    print(name) // Will print whatever was passed as the name.
And so later we can say:
Code:
sayName("John") // Will print out "John"

Hope that helps. Need any more additional help, feel free to message me.
Last edited by Strange5050; 2 years ago
1
reply
beth1234534
Badges: 9
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#3
Report Thread starter 2 years ago
#3
(Original post by Strange5050)
Def is used to marks the start of the header of a function. You can almost see it as 'define', and is used when you first 'define' a function in your program. For example.

Code:
def sayHello():
    print("Hello World")
sayHello is the function, if we were to call this function later in the program, we can simply say:
Code:
sayHello() // This will output "Hello World".
Some functions will feature what we call 'parameters', and these are basically inputs we can use in our functions:
Code:
def sayName(name):
    print(name) // Will print whatever was passed as the name.
And so later we can say:
Code:
sayName("John") // Will print out "John"

Hope that helps. Need any more additional help, feel free to message me.
That's very helpful,thank you so much !!
1
reply
beth1234534
Badges: 9
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#4
Report Thread starter 2 years ago
#4
(Original post by Strange5050)
Def is used to marks the start of the header of a function. You can almost see it as 'define', and is used when you first 'define' a function in your program. For example.

Code:
def sayHello():
    print("Hello World")
sayHello is the function, if we were to call this function later in the program, we can simply say:
Code:
sayHello() // This will output "Hello World".
Some functions will feature what we call 'parameters', and these are basically inputs we can use in our functions:
Code:
def sayName(name):
    print(name) // Will print whatever was passed as the name.
And so later we can say:
Code:
sayName("John") // Will print out "John"

Hope that helps. Need any more additional help, feel free to message me.
Name:  Screenshot 2020-01-22 at 18.47.24.png
Views: 35
Size:  125.3 KBName:  Screenshot 2020-01-22 at 18.47.37.png
Views: 35
Size:  113.7 KB Hi, super sorry to bother you again but do you know what I'm doing wrong? So confused
0
reply
Strange5050
Badges: 17
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#5
Report 2 years ago
#5
(Original post by beth1234534)
Name:  Screenshot 2020-01-22 at 18.47.24.png
Views: 35
Size:  125.3 KBName:  Screenshot 2020-01-22 at 18.47.37.png
Views: 35
Size:  113.7 KB Hi, super sorry to bother you again but do you know what I'm doing wrong? So confused
I haven't had much experience in Python, but having a quick look online, you're readData() function is being used on line 52 to assign the values of productName, price and quantity. However this function cannot be used to the assigning of a value, as the function doesn't return anything. Looking at the readData function, just call the function without the assignment of the prodcutName, price and quantity.

So in place of line 52 try:
Code:
readData()
And see if that works? If I've interpreted the code wrong then change it how you like, but the issue seems to lie in the readData() function, and the way it's being used (as I mentioned above, it's being used for assignment, but has no return value to assign).
Last edited by Strange5050; 2 years ago
1
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

What is your favourite revision method?

Taking notes manually (78)
20.63%
Note taking apps (7)
1.85%
Flashcards (86)
22.75%
Revision guides (19)
5.03%
Past papers (173)
45.77%
Something else (let us know in the thread) (15)
3.97%

Watched Threads

View All