Datatype Conditioning | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Datatype Conditioning

This code is meant to only print interger factors of the given value. Does anyone know how I do this. I used the syntax from Stack overflow but it is still printing floating point numbers. print("enter a number for the lowest common multiple") num = input() num = int(num) i = 1 while i <= 100: i = i + 1 divis = num / i if type(divis) is float: print('Not int') print(divis

22nd Mar 2019, 4:37 PM
Clueless Coder
Clueless Coder - avatar
4 Answers
+ 8
int / int will always give you an int value. If you want to get float value, in that case make either or both side float, then only the answer will be in float.
22nd Mar 2019, 5:04 PM
Letsintegreat
Letsintegreat - avatar
+ 8
Hi, just an update, I don't know if anyone can fix this, but I am trying to test a variable's datatype in an if statement. I am getting an error message saying 'str object is not callable'. Instead of making another post I thought it would be better to post in here. https://code.sololearn.com/csI7bj6Rpgcj/?ref=app
26th May 2019, 7:25 AM
Clueless Coder
Clueless Coder - avatar
+ 5
hi, getting integers instead of floates is no problem. Use a floor division: divis = num // i But for me it‘s not comlete clear what you want to do. calculating lmc needs at least 2 numbers. May be you want to achieve one number from input and as second number check the range from 1 upto input number? With: while i<= 100: you create a long list with ‘0’. Try to explain a bit more precise what you want to get.
22nd Mar 2019, 7:18 PM
Lothar
Lothar - avatar
+ 4
hi, about your vector module: When i try to run the code, i get an "indentation error" at the place where the arrays are defined. This results from en "else:" clause with no following code. I then did this: def appendVectorByType(self, index, data_type): if type(index).__name__== data_type: self.arr.append(index) print("Correct") else: pass # <-----!!!! arr1 = [] arr2 = [] index = 0 i placed a "pass" statement" - and the code executed without problem.
26th May 2019, 11:23 AM
Lothar
Lothar - avatar