how to loop a script?
 how to loop a script? ZYSIA Programmer named Tim Posts: 8 Threads: 5 Joined: Jul 2021 Reputation: Jul-22-2021, 06:29 AM (This post was last modified: Jul-22-2021, 03:02 PM by Larz60+.) Hi guys! I have create a python scripts to convert 3 random hexa number to decimal and add them together like below : however, i want to try to loop it! keep running as long as the results is less than 3. any idea how to do that? i've tried while loop doesn't work.. import random 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 #hexadecimal 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 :', dec1) hex = D2 dec2 = int(hex,16) print('Value in hexadecimal D2 :', hex) print('Value in decimal D2 :', dec2) #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) Larz60+ write Jul-22-2021, 03:02 PM:Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button Please use bbcode tags on all posts that require them! This is your 4th thread, and you have been advised on previous posts. Reply Posts: 3,120 Threads: 44 Joined: Jan 2018 Reputation: Jul-22-2021, 06:46 AM (This post was last modified: Jul-22-2021, 06:48 AM by Gribouillis.) You could use a structure such as ```result = 0 while result < 3: ... result = ...``` Reply

 Possibly Related Threads… Thread Author Replies Views Last Post for loop script over telnet in Python 3.5 is not working abhijithd123 1 1,154 May-10-2020, 03:22 AM Last Post: bowlofred Need help creating complex loop around existing script CephloRhod 5 1,038 Apr-16-2020, 01:23 PM Last Post: deanhystad Loop independent of excecution time of a script Forelli 8 1,608 Feb-02-2020, 10:49 PM Last Post: snippsat Using for loop in Python lists script? NLittle17 4 1,434 Jan-05-2019, 07:08 PM Last Post: ichabod801 How to Loop A Script within itself? HiImNew 2 1,678 Nov-22-2017, 03:09 AM Last Post: HiImNew

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020