Python Forum
struggling w/ fonctions in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
struggling w/ fonctions in Python
#1
Hello, I have several Python exercises to do in homework. I find some of them impossible to do, I hope you can help me:
"You must write a function calcule_prix(de1, de2) (de= a dice) which takes as parameter two integers between 1 and 6, the value of two dice.
If the sum is greater than or equal to 10, then you have to pay a special tax (36 pieces).
Otherwise, you pay twice the sum of the values ​​of the two integers.
Your function should display the text "Special tax!" "Or" Regular tax ", then the amount to be paid (without indicating the unit)."

This is what i have came up with:
def calcule_prix(de1, de2):
   1 <= de1 <= 6
   1 <= de2 <= 6
if de1+de2 =>10:
   print("Taxe spéciale !","36 pièces")
else:
   print("Taxe régulière","(de1+de2)*2") 


Taxe sepciale= special tax
Taxe reguliere= regular tax

Thank you in advance! Smile
Reply
#2
Please use proper code tags while posting your thread, it will be much clearer to understand
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#3
Sorry, I`m all new here. How do I use proper code tags?
Reply
#4
see BBCode
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#5
(May-08-2020, 12:23 PM)Tiril123 Wrote:
def calcule_prix(de1, de2):
   1 <= de1 <= 6
   1 <= de2 <= 6
if de1+de2 =>10:
   print("Taxe spéciale !","36 pièces")
else:
   print("Taxe régulière","(de1+de2)*2")

What shall the first 2 lines (line 2 and 3) in your function do? Delete these.
The next 4 lines need to be indented correctly
Look here what´s wrong with the if-condition
In the last line you don´t want to use that many "
Reply
#6
(May-08-2020, 03:52 PM)ThomasL Wrote: What shall the first 2 lines (line 2 and 3) in your function do? Delete these.
The next 4 lines need to be indented correctly
Indeed, he needs to check his indentation, but the first 2 lines are supposed to make sure the value is lesser than 6 as it is a dice roll.
@Tiril123, you need to change this
   1 <= de1 <= 6
   1 <= de2 <= 6
Instead, you can use an if statement, to make sure that the player enters a number less than 36. You can do :
if de1 >= 6 and de2 >= 6 :
    # your code here
else :
    print("Wrong value, needs to be lesser than or equal to 6")
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#7
(May-08-2020, 05:56 PM)pyzyx3qwerty Wrote: but the first 2 lines are supposed to make sure the value is lesser than 6 as it is a dice roll.

Read the homework of OP: "You must write a function calcule_prix(de1, de2) (de= a dice) which takes as parameter two integers between 1 and 6"

There´s no need to check values given to function.
Normally a dice is simulated using the random() function so values also don´t need to be checked.
Assuming that these values are given by user input then the validation check would be
done within another function to handle user input but NEVER within the function calcule_prix().
Reply
#8
Well, it is true he could also use an input statement telling the user to enter a value between 1 to 6 to make sure that happens .......
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Struggling on Tuples Mystix 3 4,667 Feb-01-2021, 06:06 PM
Last Post: nilamo
  How to execute several fonctions at the same time yoyo 3 2,040 Dec-22-2020, 05:46 PM
Last Post: yoyo
  Struggling with variables pythonstudy00 1 1,363 Sep-23-2020, 06:39 AM
Last Post: DPaul
  Struggling To Understand These 2 Python Files samlee916 2 1,667 Sep-22-2020, 04:50 AM
Last Post: ndc85430
  struggling with one part of python Lucifer 23 6,306 May-08-2020, 12:24 PM
Last Post: pyzyx3qwerty
  struggling with python save/load function newatpython00 1 1,916 Nov-15-2019, 07:58 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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