Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Could you help me ?
#1
Photo 
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,)
Reply
#2
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.
Reply
#3
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.
Guichel likes this post
Reply


Forum Jump:

User Panel Messages

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