This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| b_set = {5, 20, 70, 46, 50} | |
| highestNum = 0 | |
| for item in b_set: | |
| if item > highestNum: | |
| highestNum = item | |
| print("the item with the highest vale in", b_set, "is", highestNum) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| my_food_item_list = ["Garri", "Peak milk", "Bournvita", "Cornflakes", "Biscuit", "Peak milk", "Milo", "Groundnut"] | |
| first_item = my_food_item_list[0] | |
| second_item = my_food_item_list[1] | |
| fifth_item = my_food_item_list[4] | |
| print(first_item) | |
| print(second_item) | |
| print(fifth_item) | |
| # # for negative indexing | |
| item = my_food_item_list[-3] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # to check for the number of occurrence of each items in a list, here is the way to go. | |
| list = [2, 2, 3, 5, 5, 7, 7, 0, 2, 3, 1, 0, 5] | |
| dic = {} | |
| for x in list: | |
| if x in dic: | |
| count = dic[x] | |
| else: | |
| count = 0 | |
| dic[x] = count + 1 | |
| for key, value in dic.items(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| random_number = random.randint(0, 20) | |
| guess_number = input("enter your guess number: ") | |
| guess_number = int(guess_number) | |
| while random_number != guess_number: | |
| if random_number > guess_number: | |
| print("your guess is less than the random number") | |
| else: | |
| print("your guess is higher than the random number") | |
| guess_number = input("enter your guess number") |