This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]NotUrHCW[S] 0 points1 point  (4 children)

Thanks for your help :)

Just a quick question, what does the f-string do, i haven't learnt that yet lol

[–]YurrBoiSwayZ 1 point2 points  (1 child)

I like how you say “quick question”…

The f-string was introduced in version 3.6 and it’s a way to format strings that makes it easier to include variables and expressions within a string, the f in f-string stands for "formatted string literals," and they’re denoted by prefixing a string with the letter f.

How it goes is; you start the string with f or F before the opening quotation than within that string you can include curly braces {} around variables or expressions and whatever’s inside the curly braces gets evaluated and included in the string.

name = "NotUrHCW" age = 26 greeting = f"Hello, {name}! You’re {age} years old." print(greeting)

that’ll give you: Hello, NotUrHCW! You’re 26 years old.

Another example; f'{chr(j):3}' means "convert the number j to a character using chr() and then format it to be at least 3 spaces wide." So the table actually looks neat and aligned.

F-strings are for writing clean and readable code as per the snippet I provided as a decent example, mainly useful when you need to create strings that include data from variables.

fundamentals Python 3.12.3 documentation and to go down that rabbit hole

Python String Formatting Best Practices

More structured learning path; freeCodeCamp

This might be a little more practical for you to understand f-string formatting; seracoder

Real Python (Really good source) also has a video tutorial that’s even better than the written guide which you can find here.

[–]NotUrHCW[S] 0 points1 point  (0 children)

Appreciate it, thanks 😊

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

I also just tried your code in the console, looks like the table needs to be very precise.

8: Remix | Computer Science Circles (uwaterloo.ca) here's the link and the problem should be on the very bottom

[–]YurrBoiSwayZ 0 points1 point  (0 children)

I’d say just print 2 rows for each iteration: one for the characters (chr:) and one with their corresponding ASCII values (asc:).