Assignment 1 Using Len
Table of Contents
I was given a assignment and the output is and heres how you do it :).
The length of "" is 0.
The length of "H" is 1.
The length of "Hello" is 5.
The length of "Amazing" is 7.
Step 1 use print and f string we use print to display the message and f string so that when you print the program won’t become a string we also use single quotes otherwise the program doesn’t work.
print(f')
Step 2 We write the message and use len() s first we write 'The length of "" is'then we use len()but we have to put it in the sguiggly bracket{} so I don’t print len() after we do len("") and add a fullstop to make it neater and your done.
print(f' The length of "" is {len("")}.')
Heres what the code look like: :)
print(f'The length of "" is {len("")}.')
print(f'The length of "h" is {len("h")}.')
print(f'The length of "hello" is {len("hello")}.')
print(f'The length of "amazing" is {len("amazing")}.')
Extra part #
I had to do some extra bits with the same goal but even shorter. :)
Step 1. first we make a list called item put the item in the list
items = ["", "h", "hello", "amazing"]
Step 2. Next we use for loop we do i in items: and after that we use indentation print()
items = ["", "h", "hello", "amazing"]
for i in items:
Step 3. We then use f string and type the same message we then do {i} but we have to add quotation marks but to do that we escape it using the backslash \ the lastpart is to use the squiggly thing len() and at a “.” outside the squiggly
items = ["", "h", "hello", "amazing"]
for i in items:
print(f"The length of \"{i}\" is {len(i)}.")