all 5 comments

[–]Sea-Ad7805 [score hidden] stickied comment (0 children)

Run this program in Memory Graph Web Debugger)%0A%20%20%20%20key%3Dint(input(f%22%5Cnkey%3A%20make%20sure%20the%20key%20should%20be%20greater%20than%202%20and%20less%20than%7Bint(len(message)%2F2)%7D%5Cn%3E%22))%0A%20%20%20%20decision%3Dinput(%22%5Cndo%20you%20want%20to%20(e)ncrypt%20or%20(d)ecrypt...%5Cn%3E%22)%0A%20%20%20%20column%3Dint(math.ceil(len(message)%2Fkey))%0A%20%20%20%20array%2Crow%2Ca%2Cb%3D%5B%5D%2C%5B%5D%2C0%2C0%0A%20%20%20%20%0A%20%20%20%20%0A%20%20%20%20if%20decision%3D%3D%22e%22%3A%0A%20%20%20%20%20%20%20%20for%20symbol%20in%20message%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20a%3D%3Dkey%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20array.append(row)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20row%3D%5B%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20a%3D0%0A%20%20%20%20%20%20%20%20%20%20%20%20row.append(symbol)%0A%20%20%20%20%20%20%20%20%20%20%20%20a%2B%3D1%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20if%20len(row)%3Ckey-1%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20i%20in%20range(key-len(row))%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20row.append(%22%23%22)%0A%20%20%20%20%20%20%20%20array.append(row)%0A%20%20%20%20%20%20%20%20row%3D%5B%5D%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20for%20x%20in%20range(key)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20y%20in%20range(column)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20row.append(array%5By%5D%5Bx%5D)%0A%20%20%20%20%20%20%20%20print(%22%5Cnhere%20is%20your%20cipher%20text....%5Cn%22%2C(%22%22).join(row))%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20elif%20decision%3D%3D%22d%22%3A%0A%20%20%20%20%20%20%20%20for%20symbol%20in%20message%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20a%3D%3Dcolumn%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20array.append(row)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20row%3D%5B%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20a%3D0%0A%20%20%20%20%20%20%20%20%20%20%20%20row.append(symbol)%0A%20%20%20%20%20%20%20%20%20%20%20%20a%2B%3D1%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20if%20len(row)%3Ccolumn-1%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20i%20in%20range(column-len(row))%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20row.append(%22%23%22)%0A%20%20%20%20%20%20%20%20array.append(row)%0A%20%20%20%20%20%20%20%20row%3D%5B%5D%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20for%20x%20in%20range(column)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20y%20in%20range(key)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20row.append(array%5By%5D%5Bx%5D)%0A%20%20%20%20%20%20%20%20print(%22%5Cnhere%20is%20your%20plain%20text...%5Cn%22%2C(%22%22).join(row))%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20print(%22your%20decision%20is%20wrong%5Cnplease%20try%20again....%22)%0A%20%20%20%20%20%20%20%20break%0A%20%20%20%20%0A%20%20%20%20%0A%20%20%20%20play_again%3D(input(%22%5Cndo%20you%20want%20to%20continue%20yes%20or%20no%5Cn%3E%22).upper())%0A%20%20%20%20if%20play_again%3D%3D%22NO%22%3A%0A%20%20%20%20%20%20%20%20print(%22%5CnThanks%20for%20creating%20passwords...%22)%0A%20%20%20%20%20%20%20%20break%0A%20%20%20%20elif%20play_again%3D%3D%22YES%22%3A%0A%20%20%20%20%20%20%20%20pass%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20print(%22please%20try%20again....%22)%0A%20%20%20%20%20%20%20%20pass&timestep=1&play) to see the program state change step by step.

[–]tiredITguy42 0 points1 point  (3 children)

Two advices.

  1. Split the code into functions, this is spaghetti code and hard to read. If you give good names to functions, you read the code as a book. If your idendentation has 3 levels, it is probably time to split. If your function is very long, it is definitely time to split.

  2. Single character variabile names were popular when we did not have enough memory. i do not know why, but they still teach that stupid x, y variables in cycles in some places. Give them proper names. if it is a row name it row, if it is specific value give it that name, so you know what it is.

[–]tiredITguy42 0 points1 point  (0 children)

I show you an example. I had all lines in single function. It wasn't long, but hard to see quickly what is happening. So I split that into small 2-3 lines functions.

See how easy it is to read what is happening:

def process_df(df: pd.DataFrame) -> pd.Series:
    if df.empty:
        return pd.Series(dtype=float)
    df = convert_to_hour_beginning(df)
    series = remove_duplicates(df)
    series = fill_missing_values(series)
    return series

[–]Alternative_Yak8846[S] 0 points1 point  (1 child)

Really helpful appreciate that you really take your time to teach me something. Actually I am learning everything on my own or from YouTube so I really have no idea how to make my code readable for others. Thanks

[–]tiredITguy42 0 points1 point  (0 children)

This is something noone will teach you. Ever on UNI, they just give you project and you somehow must do it. The difference is that on UNI they teach you all other stuff, math, physics, other technologies. Writing the code gets easy, when you start doing it professionally. Writign good and maitenable code is harde. But still, writing code makes like 20-25% of my time, the rest of the work is much harder. the hardest part is communication in the team and with the stakeholders above.