0

I know that def is function but can somebody show the example how to use the function def?

16th Aug 2020, 1:51 PM
Kir-Py
Kir-Py - avatar
8 Antworten
16th Aug 2020, 1:56 PM
Coder Kay
Coder Kay - avatar
+ 3
https://code.sololearn.com/crQAQe8SnYPF/?ref=app I left some comments in the code to familiarise yourself with the functions
16th Aug 2020, 2:19 PM
AndreiJK
AndreiJK - avatar
+ 1
So you start with defining the balance ballance=10 Then start defining the function like this and put 2 dots and inside write what the function does then after you done that enter the main code and call it def product(milk): balance-=2 print("You bought milk") choice = input("what do you want: ") if choice == "milk": product (choice)
16th Aug 2020, 2:43 PM
AndreiJK
AndreiJK - avatar
0
AndreiJK with def function i want to write for example Def product(milk) ..... Ballance = 10 I mean i want to do that that the argument is milk and then im writing ....input=('what do u want to buy') Then i write 'milk' Then (milk costs 2 dollars...)i write 2 and then thank you for buying a milk but i can't write it its to complicate and hard for me😭😭😭😭😭😭
16th Aug 2020, 2:37 PM
Kir-Py
Kir-Py - avatar
0
AndreiJK the result i want to see: Programm : Welcome to the supermarket What do you want to buy Choice (milk , bread , donut) Me writing - milk Programm: Ok it will be 2 dollars me writing 2 And then Programm:thank you bye But if i had written 1 the programm would say :its not enough . And I want to write so with a def function but i dont know how 😭
16th Aug 2020, 2:40 PM
Kir-Py
Kir-Py - avatar
0
AndreiJK def product(milk): global ballance ballance=10 print('welcome to the supermarket') market=input('what do you want to buy') choice=input('milk', 'bread') if choice==bread: print('pay for bread 2 dollars') #then i dont know how to pay #if 1 dollar dont 2 dollars print('its not enough') if choice==milk: .......... print('bye')
16th Aug 2020, 2:55 PM
Kir-Py
Kir-Py - avatar
17th Aug 2020, 6:12 AM
Tri Satria [NEW]
Tri Satria [NEW] - avatar