Answer the question
In order to leave comments, you need to log in
Can't figure out how to fix the error?
I can’t figure out how to solve the error with the separation of characters from each other, it constantly gives an error SyntaxError : invalid syntax
(I’m just starting to learn python)
here is the code
import random
a = int(input("num1-> "))
b = int(input("num2-> "))
c = (+,-,*,/)
f = random.choice(c)
d = (a,f,b)
Answer the question
In order to leave comments, you need to log in
c = (+,-,*,/)
Naturally you will get an error. Let's first look at what can be an element of a tuple.
Spoiler:
Math operators can never be them
Instead of listing math operations in a tuple, specify them explicitly:
c = (a + b, a - b, a * b, a / b)
f = random.choice(c)
print(f)
You can pass characters to a list
. To iterate over them, you can use a loop.
symbols = ["+", "-", "*","/"]
for your_name in symbols:
...
random.choice(symbols)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question