S
S
shadowcorpse2021-09-12 22:43:17
Python
shadowcorpse, 2021-09-12 22:43:17

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

3 answer(s)
S
Saboteur, 2021-09-12
@saboteur_kiev

c = (+,-,*,/)
What do you think you are doing in this line?

K
kurrbanov, 2021-09-13
@kurrbanov

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)

V
Vitaly Yakovlev, 2021-09-13
@MerzoIT

You can pass characters to a list . To iterate over them, you can use a loop.
symbols = ["+", "-", "*","/"]

for your_name in symbols:
   ...

For your task:
random.choice(symbols)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question