Skip to content

Instantly share code, notes, and snippets.

@moelzanaty3
Last active September 15, 2022 16:49
Show Gist options
  • Save moelzanaty3/386d412075a350a97b3d6e82892202d3 to your computer and use it in GitHub Desktop.
Save moelzanaty3/386d412075a350a97b3d6e82892202d3 to your computer and use it in GitHub Desktop.
##########
# Example 1: Create a range from 0 to 10 with steps of 2
##########
#Type your code here.
rng=
print(list(rng))
####
# Hint 1: range() function can take 3 parameters. range(start, stop, step)
# Solution: rng = range(0,10,2)
#___________
##########
# Example 2: Using len() function find out how many items are in the list.
##########
lst=[11, 10, 12, 101, 99, 1000, 999]
answer_1=
print(answer_1)
####
# Hint 1: You can pass your object’s name inside len() function: len(object)
# Solution: answer_1 = len(lst)
#___________
##########
# Example 3: Sort the list in ascending order with .sort() method.
##########
lst=[11, 100, 99, 1000, 999]
#Type your answer here.
print(lst)
####
# Hint 1: .sort() method will modify the actual list and sort it.
# Solution: lst.sort()
#___________
##########
# Example 4: .insert() lets you specify the index you want to add your item.
##########
gift_list=['socks', '4K drone', 'wine', 'jam']
# Type your code here.
print(gift_list)
####
# Hint 1: .insert() takes 2 parameters: => 1st: index number, 2nd: element you’re adding: => list.insert(index, element)
# Hint 2: Remember indexing in Python starts with 0. So, first item in a list is index 0, second item in a list is index 1 and so on.
# Hint 3: Also, you don’t have to make a new assignment since, .insert method changes a list in place. This also means you might want to be careful with it when you want to preserve your original list. In those cases a good practice is creating a copy of the list and work on the copy. But, in this case you’re expected to make amends to the original.
# Solution: gift_list.insert(2, "slippers")
#___________
##########
# Example 5: Using .append() method, add a new list to the end of the list which contains strings: "Navigator" and "Suburban".
##########
lst=["CRV", "Outback", "XC90", "GL", "Cherokee", "Escalade"]
# Type your code here.
print(lst)
####
# Hint 1: .append() adds an item to the end of a list. It’s very commonly used in programming and it can be very useful.
# Hint 2: Lists are complex data types. This means it can also contain other sequences such as other lists, tuples, dictionaries etc. This creates a nested data structure and it can be very useful for larger datasets with multiple categories, labels, subcategories, genres etc.
# Solution: lst.append(["Navigator", "Suburban"])
#___________
##########
# Example 6: Using input() function ask for user's name.
##########
#Type your answer here.
ans_1=
print("Hello!, " + ans_1)
####
# Hint 1:
# input() function will return whatever user enters after its prompt. Inside
# input() function’s parenthesis you can type your message which will be shown to the user:
# input(“message or question”)
# Solution: ans_1 = input("Please enter your name.")
#___________
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment