TypeError: unsupported operand type(s) for %: 'range' and 'int'

python unsupported operand type(s) for & 'str' and 'str'
unsupported operand type(s) for 'nonetype' and 'int'
python unsupported operand type(s) for ^ 'float' and 'int'
unsupported operand type(s) for / 'str' and 'float'
typeerror: unsupported operand type(s) for +: 'int' and 'str pyspark
unsupported operand type(s) for 'nonetype' and 'str'
typeerror: unsupported operand type(s) for &: 'str' and 'bool'
unsupported operand type(s) for / 'str' and 'int' seaborn

Write a Python program to find numbers between 120 and 200 which are divisible by 7 and multiples of 5 without using a "for loop".

I tried to work it out this way...

x = range(120, 200)
if x % 7 == 0 and x % 5 == 0:
    print(x)

But rather I do get this error. What could I be missing out?

Traceback (most recent call last):
File "C:\Users\User\Desktop\skillshare-code\if else statements\4.py", line 
    11, in <module>
if x % 7 == 0 and x % 5 == 0:
TypeError: unsupported operand type(s) for %: 'range' and 'int'

Since you're not allowed to use the for construct, you can accomplish this with the filter method:

valid_nums = filter(lambda x: x % 35 == 0, range(120, 200))

Note that the problem is not asking you to print the numbers but rather "find" them which means to create some form of list or collection of the valid values

PS: I did x % 35 == 0 because "divisble by" and "multiples of" means the same thing and so 35 is from 7*5.

PPS: filter returns a filter object which is a generator. You will need to convert that to a list if you want to view the list by doing list(valid_nums). You don't need to do the conversion if you just need to iterate through the values and use them for something else since the generator will work just fine for that

TypeError: unsupported operand type(s) for +: 'int', TypeError: unsupported operand type(s) for +: 'int' and 'str' (5 + "a")? how do i fix the mistake? errors.py. print("Hello") print("name") print("hello")  Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

TypeError: unsupported operand type(s) for +=: 'int' and 'str', TypeError: unsupported operand type(s) for +=: 'int' and 'str'. The code is lovely_loveseat_description = 'text' lovely_loveseat_price = 254.00  For future reference Python is strongly typed. Unlike other dynamic languages, it will not automagically cast objects from one type or the other (say from str to int) so you must do this yourself. You'll like that in the long-run, trust me! improve this answer. answered Mar 4 '10 at 2:46. 62 silver badges. 84 bronze badges.

I think using a list comprehension is more idiomatic for Python than filter (of course if you are allowed).

x = range(120, 200)
valid_nums = [num for num in x if num % 35 == 0]

Or at creation:

valid_nums = [num for num in range(120, 200) if num % 35 == 0]

Why?? TypeError: unsupported operand type(s) for /: 'NoneType , Why?? TypeError: unsupported operand type(s) for /: 'NoneType' and 'int' TypeError: unsupported operand type(s) for -: 'list' and 'int' Hey, @William For me the code is working READ MORE. answered Mar 11 in Python by Roshni

What you are trying to do is define x as a range of numbers but that will make x a list of numbers and you will still have to go through every number to check it. Since "for loop" is not allowed, you can use a while loop or call a function recursively starting from lower limit till the passable parameter hits upper limit.

def func(x):
       if (condition satisfied):
            print(x)
       if x<upper_limit:
            func(x+1)
       return

Python error: unsupported operand type(s) for -: 'str' and 'str , print(b-a) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for -: 'str' and 'str' >>>. what can i do to divide pyc by tpy? In python 3, the input () function returns a string. This is a change from Python 2; the raw_input () function was renamed to input (). Or, potentially, floats or decimal.Decimals as appropriate, if you need to accept numbers that are not whole integers. – Gareth Latty Mar 5 '13 at 22:54.

One of my reading the challenge was to find all the numbers in a range that were divisible by 7 but not by five.

That's very different from simply reducing the problem to x % 35. Still, creating a list comprehension was the answer.

Here is what worked for me:

x = range(2000, 3201)
num = [n for n in x if n % 7 == 0 and n % 5 != 0]

Once this is done, simply print(num) and you have your answers.

TypeError: unsupported operand type(s) for -: 'str', New to coding - Python error: TypeError: unsupported operand type(s) for -: 'str' and. zer0 Offline Programmer named Tim *. Posts: 5. Threads:  Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

TypeError: unsupported operand type(s) for /: 'str' and 'str', You can divide pyc by tpy by turning them into integers instead: percent = (int(pyc​) / int(tpy)) * 100;. For python3 the input() function always  print("5" + "a") In the first example we are printing the result of adding two integers. In the second example we are printing the result of concatenating two strings. Hope this helps! on Jul 12, 2016. You are attempting to add together two different data types - python gets grumpy when we try to do this. So to get around this you can

TypeError- unsupported operand type(s) for +- 'int', TypeError: unsupported operand type(s) for +: 'int' and 'str' Python is strongly typed, which means that if you try to do an undefined operation, such as  Unsupported operand type(s) for /: 'int' and 'NoneType' I had this code working fine a couple of days ago, but all of a sudden it has stopped working. I keep getting type errors concerning my attempt to append data to data1.

TypeError: unsupported operand type(s) for +: 'int' and 'str' in Python , TypeError: unsupported operand type(s) for +: 'int' and 'str' in Python. For python, the plus “+” is used to add two numbers as well as two strings. In this instance, this is almost certainly Debian/Ubuntu's problem and not ours: you appear to be using Debian/Ubuntu's packages. That means you need to follow up with Debian/Ubuntu in the first case, as they maintain several patches and are responsible for supporting those packages in their system.

Comments
  • You need to loop through all the values in x but you're not allowed to use the for construct
  • "What could I be missing out?" % only works on single numbers, you're trying to use it on a range of numbers.
  • Most operations don't automatically loop themselves if you give them an iterable object.
  • "which are divisible by 7 and multiples of 5": your teacher has a sense of humour (and mindscrew :))
  • @Jean-FrançoisFabre I was staring at that for so long thinking, does he just mean 35? haha
  • that's probably what the (evil) teacher had in mind. You could explain the 35, and also note that filter needs to be iterated upon (wrapping it to list for instance) in python 3 else it just returns a generator.
  • but it uses a for loop inside the list comprehension.
  • @Jean-FrançoisFabre Not a Python for loop. Internally filter also uses loop.