Jul-28-2021, 09:27 AM
(This post was last modified: Jul-28-2021, 09:39 AM by Yoriz.
Edit Reason: Added code tags
)
this is my script below :
when i first run, everything is normal and prompt user "Do you want a new reading :"
but when i key in yes and the error 'str' object is not callable came out on this line "hex_number = str(hex(randomnumber))"
any idea how to solve this issue? i've check and confirm i dont have another str define else where ..
when i first run, everything is normal and prompt user "Do you want a new reading :"
but when i key in yes and the error 'str' object is not callable came out on this line "hex_number = str(hex(randomnumber))"
any idea how to solve this issue? i've check and confirm i dont have another str define else where ..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
def main(): import random global hex randomnumber = random.randint( 0 , 99 ) hex_number = str ( hex (randomnumber)) hex_numberd0 = '0x' + hex_number[ 2 :] print ( 'A random D0:' , hex_number) randomnumber = random.randint( 0 , 99 ) hex_number = str ( hex (randomnumber)) hex_numberd1 = '0x' + hex_number[ 2 :] print ( 'A random D1:' , hex_number) randomnumber = random.randint( 0 , 99 ) hex_number = str ( hex (randomnumber)) hex_numberd2 = '0x' + hex_number[ 2 :] print ( 'A random D2:' , hex_number) D0 = hex_numberd0 D1 = hex_numberd1 D2 = hex_numberd2 #hex coversion hex = D0 dec0 = int ( hex , 16 ) print ( 'Value in hexadecimal D0 :' , hex ) print ( 'Value in decimal D0 :' , dec0) hex = D1 dec1 = int ( hex , 16 ) print ( 'Value in hexadecimal D1 :' , hex ) print ( 'Value in decimal D1 :' , dec0) hex = D2 dec2 = int ( hex , 16 ) print ( 'Value in hexadecimal D2 :' , hex ) print ( 'Value in decimal D2 :' , dec0) #coversion ends #inclination calculation if (dec2 >> 7 = = 1 ): signbit = - 1 else : signbit = 1 Data0 = (dec0 >> 6 ) Data1 = (dec1 << 2 ) Data2 = ((dec2& 127 )<< 10 ) print ( "D0 =" , Data0) print ( "D1 =" , Data1) print ( "D2 =" , Data2) DataI = signbit * (Data0 + Data1 + Data2) / 1000 print ( "inclination = " , DataI) restart = input ( "Do you want a new reading : " ).lower() if restart = = "yes" : main() else : exit() main() |