Python Forum

Full Version: struggling w/ fonctions in Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
Please use proper code tags while posting your thread, it will be much clearer to understand
Sorry, I`m all new here. How do I use proper code tags?
see BBCode
(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 "
(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")
(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().
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 .......