Variable creation

Asked

Viewed 76 times

2

How do I create a variable and add the type as integer, but without having any value set? I need this variable to do this:

a = int(input())
b = int(input())
x = int # tentei colocar o tipo da variável como inteira dessa forma, mas dá erro.
if a * x == b: # a variável x precisa ser um número qualquer e inteiro para que funcione com o "if".
    print(f'O MMC entre {a} e {b} é {a}.')
  • 1

    See the question Program to find MMC in Python. If your question is like this and you solved in the way you commented, with split remainder by 2, simply nothing made sense and so I voted to close the question as unclear.

  • 2

    Lucas would be this https://answall.com/a/263153/3635 what you need?

  • 1

    Did the answer resolve what was in doubt? Do you need something else to be improved? Do you think it is possible to accept it now?

1 answer

2

Gives error because Python is a dynamically typed language, there are no types, all variables can be anything.

Actually the code doesn’t even make sense because x has no value and should not be used for anything.

Put a value on the variable and you’re done.

I doubt it will make the logic correct, but it will compile and execute without errors, then you see what you want to do with the logic.

  • If I give any value to x I will not have solved my problem, there is no way to represent x ?

  • Something worthless can’t be used either, and that’s math, not Python. If you need to solve a problem without a value, the problem is not solvable.

  • I managed to do it using the rest of the division of the two numbers.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.