Unsupported operand type s for tuple and int

Unsupported operand type s for tuple and int

Unsupported operand type s for tuple and int

Last updated: Apr 20, 2022

Here is an example of how the error occurs.

We are trying to use the subtraction operator with a tuple and a number.

If you declared a tuple by mistake, tuples are constructed in the following ways:

If you need to iterate over the tuple and subtract from each number, use a for loop.

If you need to use the subtraction operator on an item in the tuple, access the item at its specific index.

We accessed the tuple element at index 0 and subtracted 5 from it.

If you need to get the sum of the tuple, use the sum() function.

The sum function takes an iterable, sums its items from left to right and returns the total.

The sum function takes the following 2 arguments:

NameDescription
iterablethe iterable whose items to sum
startsums the start value and the items of the iterable. sum defaults to 0 (optional)

If you aren’t sure what type a variable stores, use the built-in type() class.

The type class returns the type of an object.

The isinstance function returns True if the passed in object is an instance or a subclass of the passed in class.

Помогите с кодом на Python! Ошибка: TypeError: unsupported operand type(s) for /: ‘str’ and ‘int’

Код должен определить идеальный для человека вес:

manwoman=input(‘Введите 1 если вы женщина, 2 если мужчина:’)
height=input(‘Введите свой рост:’)
if(manwoman==’1′):
totalwoman = (height*3,5/2,54-108)*0,453
print(‘Идеальный вес:’ + totalwoman )
else:
totalman = (height*4/2,54-128)*0,453
print(‘Идеальный вес:’ + totalman)

C:\Users\DAN>C:/Users/DAN/AppData/Local/Programs/Python/Python38-32/python.exe «c:/Users/DAN/Desktop/Валентин/Прога для узнавания идеального веса на питоне. py»
Введите 1 если вы женщина, 2 если мужчина: 2
Введите свой рост: 179
Traceback (most recent call last):
File «c:/Users/DAN/Desktop/Валентин/Прога для узнавания идеального веса на питоне. py», line 7, in
totalman = (height*4/2,54-128)*0,453
TypeError: unsupported operand type(s) for /: ‘str’ and ‘int’

manwoman=input(‘Введите 1 если вы женщина, 2 если мужчина:’)
height=input(‘Введите свой рост:’)
if(manwoman==’1′):
totalwoman = (int(height)*3,5/2,54-108)*0,453
print(‘Идеальный вес:’ + str(totalwoman))
else:
totalman = (int(height)*4/2,54-128)*0,453
print(‘Идеальный вес:’ + str(totalman))

Сделал так. Теперь работает, но считает не правильно. В калькуляторе формулу проверил все было верно..

Выдает: Идеальный вес: ((), 453)
А по плану должен выдавать 69 с числами после запятой..

Верный и рабочий код:

manwoman=input(‘Введите 1 если вы женщина, 2 если мужчина:’)
height=int(input(‘Введите свой рост:’))
if(manwoman==’1′):
totalwoman = (int(height)*3.5/2.54-108)*0.453
print(‘Идеальный вес:’ + str(totalwoman))
else:
totalman = (int(height)*4/2.54-128)*0.453
print(‘Идеальный вес:’ + str(totalman))

Источники:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *