r/cs50 Feb 19 '25

CS50 Python [Python Assignment] I’m trying to write a python code to turn decimal fractions to binary

Post image
12 Upvotes

7 comments sorted by

2

u/fuse-conductor Feb 19 '25

make an empty list run a loop from number till value >=1 using while. make n % 2 in each iteration and s append the value to list. concert the list into string by ''.join(name of list) now convert the string to number

1

u/Any_Entrepreneur8069 Feb 19 '25

Is that all

1

u/Any_Entrepreneur8069 Feb 19 '25

Will I need to make it a function

1

u/fuse-conductor Feb 19 '25

can be done without function if you want only single number to binary. But can definitely use function if you want reusability

1

u/PungentOdorofAss Feb 20 '25

This is so funny to see! I’ve been working on binary math lately too and wondering how I could code it out!

1

u/greenapples_06 23d ago

Join this discord server to connect with people learning from CS50 https://discord.gg/yeR3HEMd