Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 months ago.
Improve this question
import math
import random
possibility_1=0
possibility_2=0
while True:
list = [0, 1]
number_1=random.choice(list)
number_2=random.choice(list)
number_3=random.choice(list)
number_total=str(number_1)+","+str(number_2)+","+str(number_3)
if number_total==(1,1,0) or number_total==(0,0,1):
possibility_1 +=1
if number_total==(1,1,1) or number_total==(0,0,0):
possibility_2 +=1
print(str(number_total)+" possibility_11= "+ str(possibility_1)+" possibility_12= "+ str(possibility_2))
guys the possibility_1 and possibility_2 doesn!t changing. Please help me I want to make a heads or tails code and simulate it then check the possibilities.
Looks like number_total is a string so the output would be "1,1,0" you are comparing with a tuple. This means the if statements will not be invoked.
if number_total=="1,1,0" or number_total=="0,0,1":
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am currently trying to create team selection code for my python video game.
Unfortunately, it keeps highliting the ":" of my if statement and saying that it is invalid syntax, even if i change the if statement for another. I tried everything, but after all, it IS an if statement, and i can't do much.
Heres my minimal recreation of the problem. The structure is important as there is netwroking code there;
team1=[]
team2=[]
if (len(team1)+len(team2)):
if team1==team2:
rand = (random.choice([team1, team2])
if rand == "team1":
team1.append(username)
else:
team2.append(username)
else:
if team1>=team2:
team1.append(username)
else:
team2.append(username)
else:
team1.append(username)
The problem is the stray '(' you have before random.choice([team1, team2]). Delete it so it becomes:
rand = random.choice([team1, team2])
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
The code is below
i=0
a=0
Matrix[0]=0
Matrix = [1 for i in range(1000)]
while i<1000:
i=i+1
Matrix[i]=(1/1000)*((i*(1/1000))^2
a=a+Matrix[i]
print (a)
When I try to run the program, Python highlight the first a in the 8th row and it says invalid syntax.
I can't figure out what is the problem with the code.
Much appreciated if you helped
Corrected Code:
i=0
a=0
Matrix=[1 for i in range(1000)]
while i<1000:
Matrix[i]=(1/1000)*((i*(1/1000)))**2
a=a+Matrix[i]
i=i+1
print (a)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am new to python and trying to execute my code. Below is my code.
def evod(number):
if number % 2 == 0:
print("The number is even")
return"The number is odd"
print(evod(60))
Output is:
The number is even
The number is odd
if I run this function it prints both lines. It should print a single one of those. Right? Why is this happening?
if c=="July":
print("7/1/2017")
else:
print("sorry")
Indentation matters in python!
if c == "July":
print ("7/1/2017")
else:
print ("sorry")
Correct your indentation
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm trying to sort each string inside a list. For example, if I have the list ['bca', 'fed'] then I want my function to return ['abc', 'def'].
Currently trying to do this like so:
lines = [''.join.(sorted(e)) for e in lines]
What's wrong with this syntax?
Just remove the redundant dot (.):
lines = [''.join(sorted(e)) for e in lines]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Issue occurred right after I added the and x= "J1234": I don't know what's going on.
original = ""
if len(original) > 0 and x = "J123":
raw_input("Enter a word:")
original = raw_input('word')
print "original"
else:
print "empty"
x.isalpha()
So, you're getting a SyntaxError. To fix this, change:
x = "J123":
to...
x == "J123":
In Python the former is for setting values and the latter is for checking them. Therefore when you use this the wrong way round the syntax is incorrect.