I try to make a sudoku solver program. I want to get the variables who matches(positive-the true variables) with if-else statement. I make an example.
a = int(input("Write a number (1-9)"))
b = int(input("Write a number (1-9)"))
c = int(input("Write a number (1-9)"))
d = int(input("Write a number (1-9)"))
if (a = 2 or b = 2 or c = 3 or d = 4):
print("if the user prints 2 for "a" variable I want to print here "a = 2" ")
It is better to do in multible if
statements, otherwise you can not determine which value has user entered. Implementation would be:
if a==2:
print("a == 2")
elif b==2:
print("b == 2")
elif c==3:
print("c == 3")
elif d==4:
print("d == 4")
Also you need to use ==
for comparing, not =
which used in assignments.
Not sure what is the question, is this something you're looking for:
print('a=%s, b=%s, c=%s, d=%s' % (a, b, c, d))
This will print: a=1, b=2, c=3, d=4
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.