Assignment 5: Elements and Indices

Today I had to do another assignment which is to create a python program which prints the elements of a list followed by their corresponding indices. Each element and its index must be on the same line seperated by a space. And if the list is empty, print “Empty List”. I’m going to make a list called num and put 1 to 4 inside. num = [1, 2, 3, 4] Then I’ll use the if statement to do: ...

November 11, 2023 · 2 min · SourFox

Assignment 4: Checking if a list is empty

I was given an assignment for the fourth time. My goal was to write a python program that checks if a list is empty or not. If the list is empty, then it’ll print empty, if not, it’ll print not empty. I’m going to start with an empty list. emp = [] So that I can start the next step. I’m going to use if statement len() else print() When using if, there must be a condition met. My condition is: ...

October 29, 2023 · 1 min · SourFox

Assignment 1: Using Length and String

Today, I was given an assignment. My assignment wanted me to write a Python program that pints the length of a string. This is what I had to print out: The length of "" is 0. The length of "H" is 1. The length of "Hello" is 5. The length of "Amazing" is 7. To do this, I have a plan in my mind which is: Step 1. Find out what I’m going to use. ...

October 15, 2023 · 3 min · Soure Fox

Assignment 2: Python Using Lists and While-Loop

I had an assignment that I was given for Python. What I have to do is to write a program in Python that asks a user to enter their favourite fruit, store each fruit in a list. At the end of the program, print out the total number of fruits, and also print all the fruits. This is what I’m expected: What is your favourite fruit? Banana (the fruit user put) What is your favourite fruit? Apple (the fruit user put) What is your favourite fruit? Orange (the fruit user put) What is your favourite fruit? (empty) (the user didn't write anything) You have 3 fruits in the basket: Banana, Apple, and Orange. So how do I do this? ...

October 7, 2023 · 5 min · SourFox

Display Items in Python List

Today, I was asked to write a small python code to print out all items in a list with comma seperated. The last item would end the with a ‘dot’, or full stop. For example, here is a list of sports: sports = [ 'basketball', 'soccer', 'netball' ] And I was asked to print out the expected output: My favourite sports are: basketball, soccer, netball. But how do I do this? Today, I’ll be showing you how to show the expected output using join and without join. ...

October 2, 2023 · 3 min · SourFox