Python Forum

Full Version: Could you help me ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have the folowing program and I don't understand why it says hat there is an error on the line n°8.
Could someone help me fix he bug please?

from random import *
a=0
b=0
d=0
n=int(input("Combien de déplacements?"))
for i in range(1,n+1):
d=randint(1,4)
if d=1:
a=a+1
elif d=2:
a=a-1
elif d=3:
b=b+1
elif d=4:
b=b-1
print("L'abscice du point au bout de",n,"déplacements est de",a,)
print("L'ordonée du point au bout de",n,"déplacements est de",b,)
It would help if you posted the full traceback of the error. Also, please make sure to post code within "[python]" tags to preserve formatting and add line numbering and syntax highlighting.
Hi Guichel, welcome to the forum.
First: please read BBCode. When you post Python code you should put "Pyton" tags around it so the indentation is retained.
Second: an error message always contains important information about what exactly goes wrong. So always include the error message in "error" tags.
Third: if I'm counting right, line 8 is:
if d=1:
Now in Python "=" means assignment. So d gets the value "1". But I believe you mean to compare values. So you should use "==" for comparison.
I hope this helps.